1

テーブル行内のボタンが行に添付されたイベントをトリガーしないようにしようとしています

この解決策は機能しますが、私はそれが好きではありません:

$('table.orders tr.item').live('click',function(){
    var id=$(this).attr('hrf');
    document.location.href = id;
});
$('table.orders tr.item .pdfIcon').live('click',function(e){
e.stopPropagation();
}); 

最初のイベントが機能しないようにするために2番目のイベントを添付するというアイデアは好きではありません。選択から削除できるはずです。

誰かがより良い方法を提案できますか?

4

3 に答える 3

1
$('table.orders').on('click', 'tr.item', function (event) {
    if (!$(event.target).hasClass('pdfIcon')){
        var id=$(this).attr('hrf');
        document.location.href = id;
    }
});
于 2013-03-23T07:32:15.590 に答える
0

どうですか

$('table.orders tr.item').live('click',function(e){
    if ($(e.target).is('.pdfIcon')) return;
    var id=$(this).attr('hrf');
    document.location.href = id;
});
于 2013-03-23T07:31:09.953 に答える
0

試す

$('table.orders').on('click', 'tr.item', function(event) {
    if ($(event.target).hasClass('pdfIcon')) {
        return;
    }
    var id = $(this).attr('hrf');
    document.location.href = id;
});

デモ:フィドル

于 2013-03-23T08:10:54.637 に答える