Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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
jQuery单击表单元格事件_Jquery_Html Table_Cell - Fatal编程技术网

jQuery单击表单元格事件

jQuery单击表单元格事件,jquery,html-table,cell,Jquery,Html Table,Cell,我有一个如下的html代码 <tbody> <tr id="info"> <td class="name">Joe</td> <td class="surname">White</td> <td class="age">25</td> </tr> </tbody> 当我点击td时,功能\u td可以正常工作,但功能\u tr也可以工作。 如何防止

我有一个如下的html代码

<tbody>
  <tr id="info">
    <td class="name">Joe</td>
    <td class="surname">White</td>
    <td class="age">25</td>
 </tr>
</tbody>
当我点击
td
时,
功能\u td
可以正常工作,但
功能\u tr
也可以工作。
如何防止
功能?

您需要使用

$("tr#info").click(function() {        // function_tr
  $(this).css("background-color","yellow");
});

$("tr#info td").click(function() {     // function_td
  $(this).css("font-weight","bold");
});
$("tr#info td").click(function(e){     //function_td
  $(this).css("font-weight","bold");
  e.stopPropagation();
});
$("tr#info td").click(function(e){     //function_td
  $(this).css("font-weight","bold");
  e.stopPropagation();
});