开发者

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 di开发者_如何学运维sabling 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜