Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 限制特定列的单击事件_Javascript_Jquery_Css_Html - Fatal编程技术网

Javascript 限制特定列的单击事件

Javascript 限制特定列的单击事件,javascript,jquery,css,html,Javascript,Jquery,Css,Html,有人能告诉我如何禁用特定列的点击事件吗 场景:我们在一个表中显示用户详细信息,一旦在表行上单击,弹出的对话框窗口将显示更多详细信息(调用ajax请求从数据库中检索详细信息)。但我们的约束是对与表关联的单个列禁用单击事件 例如: 名称 身份证件 电话号码 克鲁帕 123 如果对文本(第1列和第2列)进行了单击,它将调用单击事件。但若用户点击超链接(第三列),我想将其重定向到Google,但不想点击事件(testing()) 有人能帮我实现这一点吗 //snip <tr> <t

有人能告诉我如何禁用特定列的点击事件吗

场景:我们在一个表中显示用户详细信息,一旦在表行上单击,弹出的对话框窗口将显示更多详细信息(调用ajax请求从数据库中检索详细信息)。但我们的约束是对与表关联的单个列禁用单击事件

例如:


名称
身份证件
电话号码
克鲁帕
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();
            }
       });

});