How to execute Jquery code only once??

后端 未结 9 2070
梦谈多话
梦谈多话 2020-12-16 15:52

I have one jquery method and i used call that method on click of a button . So in that code i have one line \" $(\"#loadingMessage\").css(\'padding-top\',\'6%\');

9条回答
  •  北海茫月
    2020-12-16 16:35

    Use jQuery .one(). When using .one() method, the event handler function is only run once for each element.

    $('#SearchButton').one("click", function () {
        $("#loadingMessage").css('padding-top', '6%');
    });
    
    $('#SearchButton').click(function () {
        $(".spinner").css('visibility', 'hidden');
    
        loaderStart();
        document.getElementById('loadinggif3').style.display = "block";
        $("#loadinggif3").show();
        $(".col-sm-9").css('visibility', 'hidden');
        var str = $('#SearchText').val();
        str = str.trim();
        if (str == "") return false;
    });
    

提交回复
热议问题