使用 javascript 或 jquery 禁用鼠标双击
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5241981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable mouse double click using javascript or jquery
提问by Fatih Acet
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.
现在的问题是,如果我双击文本框,它也会转到另一个页面,所以,我需要禁用在此文本框上单击鼠标,并使用 tr 作为标题,另一个 tr 用于数据。当我单击 tr 标题时,它也应该不工作。
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.
我有很多文本框,所以让每一个双击鼠标禁用都不是很好的解决方案。如果我单独单击带有数据的行,双击应该可以工作。
采纳答案by Praveen Prasad
add a class='myClickDisabledElm'
to all DOM elementswhose clicks you want to stop.
将 a 添加class='myClickDisabledElm'
到您想要停止点击的所有 DOM 元素。
<input type="text" class="myClickDisabledElm" />
now javascript
现在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
由于您更关心 abt 双击,您可以使用dblclick
代替click
回答by Fatih Acet
it should be like this
应该是这样的
$('.myTextBox').dblclick(function(e){ e.preventDefault(); })
回答by Becheru Petru-Ioan
回答by Siva Kameswara Rao Munipalle
Got the following code from here
从这里得到以下代码
jQuery code to disable double click event on the webpage.
用于禁用网页上的双击事件的 jQuery 代码。
$(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,
上面的 jQuery 代码将禁用网页上所有控件的双击事件。如果您想禁用特定控件,假设一个 ID 为“btnSubmit”的按钮,然后,
$(document).ready(function(){
$('#btnSubmit').dblclick(function(e){
e.preventDefault();
});
});
回答by assassin
If you want to disable any mouse click action use addEventListener(event, function, useCapture) .
如果要禁用任何鼠标单击操作,请使用 addEventListener(event, function, useCapture) 。
Onclick ,call this function.
Onclick ,调用这个函数。
For more refer here.: https://www.w3schools.com/jsref/met_element_addeventlistener.asp
有关更多信息,请参阅此处。:https: //www.w3schools.com/jsref/met_element_addeventlistener.asp