jQuery单击表格单元格事件
我有一个像下面的HTML代码
Joe White 25
并且有一个像这样的jQuery代码:
$("tr#info").click(function() { // function_tr $(this).css("background-color","yellow"); }); $("tr#info td").click(function() { // function_td $(this).css("font-weight","bold"); });
当我点击td
, function_td
工作正常,但function_tr
也可以。
如何防止function_tr
?
你需要使用event.stopPropagation()
$("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(); });