Disable mouse double click using javascript or jquery

前端 未结 5 2004
借酒劲吻你
借酒劲吻你 2021-01-05 07:17

I have a form in which i have some text boxes and below to it there is a table.When i double click on table row it takes me to another page.

Now the problem is if i

相关标签:
5条回答
  • 2021-01-05 07:49

    If you want to disable any mouse click action use addEventListener(event, function, useCapture) .

    Onclick ,call this function.

    For more refer here.: https://www.w3schools.com/jsref/met_element_addeventlistener.asp

    0 讨论(0)
  • 2021-01-05 07:55

    it should be like this

    $('.myTextBox').dblclick(function(e){ 
        e.preventDefault();
    })
    
    0 讨论(0)
  • 2021-01-05 08:00

    As said here, use a capture phase event listener:

    document.addEventListener( 'dblclick', function(event) {  
        alert("Double-click disabled!");  
        event.preventDefault();  
        event.stopPropagation(); 
      },  true //capturing phase!!
    );

    0 讨论(0)
  • 2021-01-05 08:01

    add a class='myClickDisabledElm' to all DOM elements whose clicks you want to stop.

    <input type="text" class="myClickDisabledElm" />
    

    now javascript

    jQuery('.myClickDisabledElm').bind('click',function(e){
        e.preventDefault();
    })
    

    Edit

    Since you are more concerned abt double click you may use dblclick in place of click

    0 讨论(0)
  • 2021-01-05 08:02

    Got the following code from here

    jQuery code to disable double click event on the webpage.

    $(document).ready(function(){
          $("*").dblclick(function(e){
            e.preventDefault();
          });   
        });
    

    Above jQuery code will disable double click event for all the controls on the webpage. If you want to disable for specific control, let's say a button with ID "btnSubmit" then,

    $(document).ready(function(){
          $('#btnSubmit').dblclick(function(e){
            e.preventDefault();
          });   
        });
    
    0 讨论(0)
提交回复
热议问题