我的 html 文件中有此代码
{% for dimension in dimension_list %}
<tr>
<td>{{dimension.title}}</td>
<td>{{dimension.description}}</td>
<div class="button-group">
<td><button type="button" class="delete btn" id="btn-confirm-del" ><i class="fa fa-trash"></i></button></td>
</div>
</tr>
{% endfor %}
如何获取dimension.title
用户点击按钮时的值#btn-confirm-del
?
我想在模态上显示它。
您可以在 jquery 中使用最接近的方法
$('.delete').on('click', function(){
var dTitle = $(this).closest('tr').find('td:first-child').text()
alert(dTitle);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>{{dimension.title}}</td>
<td>{{dimension.description}}</td>
<td>
<div class="button-group">
<button type="button" class="delete btn" >delete<i class="fa fa-trash"></i></button>
</div>
</td>
</tr>
<tr>
<td>{{dimension.title}}</td>
<td>{{dimension.description}}</td>
<td>
<div class="button-group">
<button type="button" class="delete btn" >delete<i class="fa fa-trash"></i></button>
</div>
</td>
</tr>
</table>
我希望这能帮到您
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句