单击表格复选框时不打开新页面 [英] Not to open a new page when table check box is clicked
本文介绍了单击表格复选框时不打开新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个JavaScript,当我点击表格行时会打开新页面:
I have this JavaScript which opens new page when I click on a table row:
$(document).ready(function () {
$('table[id$="dataTable"]').find("tbody").on("click", "tr", function () {
$(this).find('a[id$="lnkHidden"]').trigger("click");
}).on("click", 'a[id$="lnkHidden"]', function (e) {
e.stopPropagation();
});
});
JavaScript用于调用此按钮:
The JavaScript is used to call this button:
<h:commandLink id="lnkHidden" action="#{bean.pageRedirect}" style="text-decoration:none; color:white; display:none">
<f:setPropertyActionListener target="#{bean.sessionValue}" value="#{item.value}" />
</h:commandLink>
代码效果很好但事实证明当我选择表格的第一列是复选框我也打开一个新页面。如何在单击复选框时修改JavaScript不打开新页面?
The code works well but it turns out that when I select the first column of the table which is a check box I also open a new page. How I can modify the JavaScript not to open a new page when the check box is clicked?
推荐答案
监听表格单元格的点击而不是行,然后忽略第一列中的单元格。
Listen for clicks on table cells instead of rows, then ignore if the cell's in the first column.
坚持使用jQuery,这可能有效:
Sticking with jQuery, this might work:
$(document).ready(function () {
$('table[id$="dataTable"]').find("tbody").on("click", "td", function () {
if (this.cellIndex > 0) {
$(this.parentNode).find('a[id$="lnkHidden"]').trigger("click");
}
}).on("click", 'a[id$="lnkHidden"]', function (e) {
e.stopPropagation();
});
});
这篇关于单击表格复选框时不打开新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文