click() firing multiple times

前端 未结 3 1387
心在旅途
心在旅途 2021-01-21 09:21

I am using a document.getElementById(\"val\").click() to invoke a click event, but it keeps firing multiple times.

Here I add the eventHandler:



        
3条回答
  •  孤独总比滥情好
    2021-01-21 09:54

    try hooking it up with 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');
        });
     });
    

    This could be even more concise, depending on how your arrows and Buttons are laid out in the DOM. Potentially it could be a single line of jQuery.

    Something like:

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

提交回复
热议问题