簡體   English   中英

防止事件使用jQuery進一步傳播

[英]Prevent a event from propagating further using jQuery

我有一個點擊事件

<input type="button" id="button1" value="Submit" />

$('#button1').bind('click', function(e){
    e.stopPropagation();
    e.stopImmediatePropagation();
    alert('Loading, please wait...');
});

但是,不會阻止出現alert消息。 如何在alert之前停止事件。

您需要return false; 你打算在這里做什么

$('#button1').bind('click', function(e){
    e.stopPropagation(); //stops propogation of click to parent elements
    return false; //stops further execution
    alert('Loading, please wait...');
});

演示小提琴

$('#button1').bind('click', function(e){
        return false;
        alert('Loading, please wait...');
    });

用這個。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM