简体   繁体   中英

set an anchor tag's href to a value to make it unresponsive to javascript/jquery methods on the page

so i have a jquery function that does something on the click of an anchor tag.now i want to make the button unresponsive to jquery on subsequent clicks. what should i do? what i am doing is changing the innerHTML of the anchor tag on the first click and doing an AJAX call and during this time period i want nothing to happen when the user click on the same anchor tag again.

This is how i handle clicks through jquery

  $('.profileEdit label a').live('click', function () {
     // do something
  });

If i understood what you want you can just remove the 'onclick' attribute before the ajax call and set it up again at the end (success or fail).

@EDIT: final solution codes

function update(){
$("#bb").html('Updating');
$("body").off('click',"#bb");
 $.ajax({
            type: "POST",
            url:"profileUpdate.asmx/HelloWorld",
            data: "{ 'value': '" + document.getElementById(string).value + "'" + ",'column':'" + string  + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                defaultSetter();                  
            },
            error: function (msg) {
                defaultSetter();
            }
        });

}

function defaultSetter(){
    $("#bb").html("Test");
    $("body").on('click','#bb', update);
}

$(document).ready(function(){
    defaultSetter();
});

jsfiddle: http://jsfiddle.net/V3AAF/

bb element is a button, not an anchor

Could you not just use one() if you only want the action to happen once on the first click?

$('.profileEdit label a').one('click', function () {
     alert('This will only alert on the first click');
});

If you happened a handler for further clicks on that element, just use return false, to prevent anything from happening after the first click:

$('a').on('click', function () {
    return false;
    alert('first time!');
});

jsFiddle example.

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