开发者

Using two functions with table

I made a little listview widget which uses a table and assigned a function to its rows like:

$("tr",myTable).bind("click",function(){
    selectRow($(this));
});

I now would like to apply another function called deleteRow, but only to each row's last cell:

$("td:last-child",myTable).bind("click&quo开发者_运维知识库t;,function(){
    deleteRow($(this));
});

My question: when clicking the last cell for deleting a row, I don't want the selectRow function to be fired - how can I avoid this?


You can stop the click from bubbling up to the <tr>, like this:

$("td:last-child",myTable).bind("click",function(e){
    deleteRow($(this));
    e.stopPropagation();
});

Since your other click handler is on the <tr>, it won't fire, since you stopped it from bubbling up using event.stopPropagation().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜