jquery - 添加行点击功能后表格行中的按钮不起作用
问题描述
我正在使用 bootstrap 4 并获得了一个表格,其中表格行是可点击的。每行还有两个按钮。但是按钮不再起作用,因为它正在执行行单击所做的任何事情。
这是一个示例表
<table id="subjects" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th class="d-none">IDs</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr data-href="subjects/blah">
<td nowrap class="d-none">
<div>121212</div>
</td>
<td>
<button type="button" class="btn btn-dark" onclick="location.href='subject/fff'">Edit</button>
<button type="button" class="btn btn-dark" data-toggle="modal" data-target="#confirm-delete" data-href="subject/delete/blah">Delete</button>
</td>
</tr>
</tbody>
</table>
<script>
$(document).ready(function() {
$('.table tr[data-href]').each(function(){
$(this).css('cursor','pointer').hover(
function(){
$(this).addClass('active');
},
function(){
$(this).removeClass('active');
}).click( function(){
document.location = $(this).attr('data-href');
}
);
});
});
</script>
第一个按钮有一个 onclick,第二个按钮打开一个引导模式对话框。
目前这些按钮都不起作用,直到我删除表格行 jquery 单击功能。我怎样才能让它工作得很好?
解决方案
$('.table td.row-link').each(function(){
$(this).css('cursor','pointer').hover(
function(){
$(this).parent().addClass('active');
},
function(){
$(this).parent().removeClass('active');
}).click( function(){
document.location = $(this).parent().attr('data-href');
}
);
});
推荐阅读
- firebase - 投票系统 Firebase 安全规则
- java - 如何正确使用字节数组中的 SecureRandom 输出?
- c++ - CMake:为什么added_subdirectory对其他子目录不可见
- android - Butterknife.bind 布局问题
- python - 从使用多个 .py 文件的 python 程序创建 exe
- java - Android/Java 中的 Apidaze REST API HTTP POST 调用
- c# - Unity JSON 字符串数组从 cUrl 转换为对象
- dart - 将变量附加到文本字段的文本
- gnuplot - 在gnuplot中绘制能量产生率
- log4j2 - OpenJPA + Log4j2