Javascript 限制特定列的单击事件
有人能告诉我如何禁用特定列的点击事件吗 场景:我们在一个表中显示用户详细信息,一旦在表行上单击,弹出的对话框窗口将显示更多详细信息(调用ajax请求从数据库中检索详细信息)。但我们的约束是对与表关联的单个列禁用单击事件 例如:Javascript 限制特定列的单击事件,javascript,jquery,css,html,Javascript,Jquery,Css,Html,有人能告诉我如何禁用特定列的点击事件吗 场景:我们在一个表中显示用户详细信息,一旦在表行上单击,弹出的对话框窗口将显示更多详细信息(调用ajax请求从数据库中检索详细信息)。但我们的约束是对与表关联的单个列禁用单击事件 例如: 名称 身份证件 电话号码 克鲁帕 123 如果对文本(第1列和第2列)进行了单击,它将调用单击事件。但若用户点击超链接(第三列),我想将其重定向到Google,但不想点击事件(testing()) 有人能帮我实现这一点吗 //snip <tr> <t
名称
身份证件
电话号码
克鲁帕
123
如果对文本(第1列和第2列)进行了单击,它将调用单击事件。但若用户点击超链接(第三列),我想将其重定向到Google,但不想点击事件(testing())
有人能帮我实现这一点吗
//snip
<tr>
<td onclick = "testing()"> Krupa </td>
<td onclick = "testing()"> 123 </td>
<td> <a href = "http://www.google.com" target= '_blank'>Click me </a> </td>
</tr>
//snip
//snip
克鲁帕
123
//剪断
试试这个
将名为templatecell
的类添加到相应的td以防止单击
<table border = '1'>
<tr>
<th> Name </th>
<th> Id </th>
<th> Phone Number</th>
</tr>
<tr onclick = "testing()">
<td> Krupa </td>
<td> 123 </td>
<td class="templatecell"> <a href = "http://www.google.com" target= '_blank'>Click me </a> </td>
</tr>
</table>
功能测试(){
警报(“测试”)
}
$(文档).ready(函数(){
$('table tr td')。单击(函数(){
if($(this).index()<2){
测试();
}
否则{
//window.open($(this.find('a').attr('href'));//正在工作
$(this)。查找('a')[0]。单击();
}
});
});
<table border = '1'>
<tr>
<th> Name </th>
<th> Id </th>
<th> Phone Number</th>
</tr>
<tr onclick = "testing()">
<td> Krupa </td>
<td> 123 </td>
<td class="templatecell"> <a href = "http://www.google.com" target= '_blank'>Click me </a> </td>
</tr>
</table>
$("table").on("click","td", function(e){
if($(e.target).closest(".templatecell").length){
//Clicked hyper link
//do action and return from here
return;
}
//Else clicked on td cell show popup
})
function testing() {
alert('testing')
}
$(document).ready(function () {
$('table tr td').click(function () {
if ($(this).index() < 2) {
testing();
}
else {
// window.open($(this).find('a').attr('href')); //working
$(this).find('a')[0].click();
}
});
});