简体   繁体   中英

Disable mouse double click using javascript or jquery

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 double click on text boxes also it is going to another page so,i need to disable mouse clicks on this text boxes and also used tr for header and another tr for data.when i click tr header also it should n't work.

Note:

i have many text boxes so making each one double click mouse disabling is n't good solut.If i click row with data alone that double click should work.

it should be like this

$('.myTextBox').dblclick(function(e){ 
    e.preventDefault();
})

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

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!! ); 

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();
      });   
    });

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM