0

現在、クリック時に子要素の色を変更しようとしています。親要素は別のページにリンクしています。stopPropogation が機能することを望んでいましたが、そうではありません。以下は私のjQueryコードです:

$('.child').click(function(){

    if($(this).hasClass('pinned')){

        $(this).removeClass('pinned')

    }

    else{

        $(this).addClass('pinned')

    }

}); 

    // disable parent link when pinning

    $('.child').click(function(event){

        event.stopPropagation();

    }); 

問題がある場合は、アンカー タグで祖父母を囲みます。

どこが間違っていますか?

4

1 に答える 1

1
$('.child').click(function(e) {
    if($(this).hasClass('active')){
        $(this).removeClass('pinned');
    }
    else {
        $(this).addClass('pinned');
    }
    e.stopPropagation();
    return false;
}); 

e.stopPropagation同じ機能で使用できます。

于 2013-02-22T04:35:29.260 に答える