问题描述:

I want to call a function on one type of button click on my HTML page.

I have got around 10 such button on the page and wrote the below code to call a function when the button is clicked,

$('.divname').each(function (index) {

$(this).on("click", function (e) {

//Call Another Function

});

});

And this is working fine as expected.

However the issue is, sometimes depending on some condition one dynamically generated div is been created(Pop up message) and I dont want my above said code to work when the pop up message comes up.

Could you please advise how this can be achieved.

Thanks and Regards,

Aniket

网友答案:

Hi What something like set a bool and check if it true or false...somthing like:

var enable = true;

$('.divname').each(function (index) {
    $(this).on("click", function (e) {
        //Call Another Function
if(!enable) return;
    });
});

//set it to false on popup show (or something else event)
    $(popup).show(function(){
       enable = false;
    })
网友答案:

In simplest way.

$('.divname').each(function (index) {
    $(this).on("click", function (e) {
        //Simply check the condition for that Open Pop up message
       if(openPopUp){
       return;
       }
      callfunction();
    });
});
网友答案:

try something,

$('.divname').each(function (index) {
    $(this).on("click", function (e) {
       if($('#popupModal:visible').length == 0){ // check length of visible modals
        //Call Another Function
       }
    });
});
相关阅读:
Top