Press () several times

I use document.getElementById("val").click()to trigger a click event, but it continues to fire several times.

Here I add eventHandler:

try {
    //add mousedown event handler to navigation buttons
    addEventHandler(oPrevArrow, "mousedown", handlePrevDayClick);
    addEventHandler(oNextArrow, "mousedown", handleNextDayClick);
    addEventHandler(oLogout, "mousedown", handleLogoutClick);
} 
catch (err) {
}

In the click event, I perform an "automatic click"

function handleNextDayClick(e) {
    e = e || window.event;
    stopEvent(e);
    document.getElementById("btn_nextday").click();
}

I need help to find out what makes him call several times, and a possible solution.

Note: a button that is automatically clicked invokes a method in ASP.NET Code-Behind

+3
source share
3 answers

, , , , , . , , , , , . .

+2

JQuery:

 $(document).ready(function() {
    $('#oPrevArrow').click(function() {
        $('#btn_prevday').trigger('click');
    });
    $('#oNextArrow').click(function() {
        $('#btn_nextday').trigger('click');
    });
    $('#oLogout').click(function() {
        $('#btn_logout').trigger('click');
    });
 });

, , DOM. jQuery.

- :

 $(document).ready(function() {
    $('.arrow').click(function() { //note css class selector
        $('this + button').trigger('click');
    });
 });
+1

- , .

, , :

, .die().

And then attach the method listener.

In this way,

$('.arrow').click(function() {
// FUNCTION BODY HERE
}

it should be:

$('.arrow').die("click")
$('.arrow').click(function() {
// FUNCTION BODY HERE
}
0
source

Source: https://habr.com/ru/post/1759178/


All Articles