带有链接未选中复选框的 HTML 表格行
HTML Table row with link not checking checkbox
我有一个在PHP中回显的HTML表:
echo '<tr class="notfirst" style="cursor:pointer;" onclick="document.location=''editinvoice.php?seq='.$result["sequence"].'&inv='.$result["invoice_number"].'''">
<td width="20"><input type="checkbox" name="check'.$counter.'" id="check'.$counter.'" onclick=''add('.$total.', this);'' /></td>
<td width="150">'.$result["invoice_number"].'</td>
<td width="250">'.$company.'</td>
<td width="100">'.$date.'</td>
<td width="100">£'.$result["total"].'</td>
<td width="100">£'.$result["total"].'</td>
</tr>';
因此,当您将鼠标悬停在它上面时,它会突出显示整行,无论您单击该行的哪个位置,它都会打开链接,但是当我选中复选框时,它也会打开链接 - 我想停止此操作
我认为最好
将javascript代码与html标记分开。这样你就可以更好地控制它。
看看 javascript 中的冒泡阶段,看看 preventdefault我希望这有帮助
我会使用event.stopPropagation()
这是一个jQuery版本,因为它更容易做到,但如果必须,你可以在DOM访问中重写它。如果这样做,还需要为 IE<9 添加event.cancelBubble=true
$(function() {
$(".notfirst").on("click",function() {
location = "editinvoice.php?seq="+$(this).data("seq")+"&inv="+$(this).data("inv");
});
$("checkbox[name^=check]).on("click",function(event) {
event.stopPropagation();
add($(this).data("total");
});
});
使用此代码:
echo '<tr class="notfirst" style="cursor:pointer;" data-seq="'.$result["sequence"].'" data-inv="'.$result["invoice_number"].'">
<td width="20"><input type="checkbox" name="check'.$counter.'" id="check'.$counter.'" data-total="'.$total.'" /></td>
<td width="150">'.$result["invoice_number"].'</td>
<td width="250">'.$company.'</td>
<td width="100">'.$date.'</td>
<td width="100">£'.$result["total"].'</td>
<td width="100">£'.$result["total"].'</td>
</tr>';
相关文章:
- 将HTML表格导出到excel时,无法将数据加载到excel文件中
- 打印预览没有应用程序页眉和页脚的html表格
- 将HTML表格导出到带有文本和图像的excel中
- JS图表和html表格重叠
- 带有单选按钮的html表格复制粘贴到xls中
- HTML表格导出为具有适当列宽和字体的pdf
- html表格的浮动水平滚动条
- 如何在不导致 HTML 表格失真的情况下正确使用追加
- ModalDialog:HTML表格应该是可滚动的,而不是整个页面
- HTML表格在打印后缺少边框颜色和背景颜色
- 使用 javascript 为 HTML 表格单元格指定颜色
- 如何自动从一个页面移动到另一个页面,然后回到 html 表格中分页的第一页
- 提交表单时如何在 HTML 表格中添加行
- 将Google电子表格转换为HTML表格
- 单击并用CTRL+C复制值时高亮显示html表格单元格
- 使用TableExport.js将HTML表格导出为PDF、WORD、PNG
- 打印html表格而不提示预览窗口
- 将html表格导出为word文件并更改文件方向
- 如何将表格html表格导出为PDF
- 如何访问HTML表格单元格中的选择