简体   繁体   中英

Why does a bound event activate twice in jQuery?

I have some HTML:

<div class="form-item">
 <a id="listStandardsLink" target="_blank" class="" href="/connect/arisbrowser/standards">Select Standards</a>
</div>

And my javascript is:

    $("#listStandardsLink").click( function(e) {
        alert("HARD");
        // DO STUFF

        return false;
    });

For some reason, I get TWO alerts when I click it. Any ideas?

If you are not sure where else you are binding the click event try to unbind the event before you bind it.

$("#listStandardsLink").unbind('click').click( function(e) {
        alert("HARD");
        // DO STUFF

        return false;
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM