admin管理员组文章数量:1425135
I want to trigger double click event on any element when a single click event occurs in that element.
To be more clear, let's say I have a text box with some text, and when the user clicks(single click) on the text box I have to trigger that single click to multiple clicks(either double click or even tripple click).
I tried the following way, but in vain :(
$('#timer').click(function() {
$('#timer').dblclick();
});
Thanks in advance.
Cheers!
I want to trigger double click event on any element when a single click event occurs in that element.
To be more clear, let's say I have a text box with some text, and when the user clicks(single click) on the text box I have to trigger that single click to multiple clicks(either double click or even tripple click).
I tried the following way, but in vain :(
$('#timer').click(function() {
$('#timer').dblclick();
});
Thanks in advance.
Cheers!
Share Improve this question edited Jul 11, 2011 at 9:44 kxhitiz asked Jul 11, 2011 at 9:38 kxhitizkxhitiz 1,9494 gold badges19 silver badges26 bronze badges 4- The pseudo-code you have here would result in three clicks - the original user click and then two triggered clicks. However, it may be more important to ask what you want to do with these double clicks. I'm assuming that some other app is listening for double clicks? If that is the case, a double-click is usually defined as having some interval between the two clicks so you need to take that into account. – T Nguyen Commented Jul 11, 2011 at 9:51
- It depends on whether the actual number of clicks is important or you merely want the 'double-click' event to be triggered. – vinod Commented Jul 11, 2011 at 9:53
- Sometimes, revising our business is a more intelligent decision. I think you'd better tell us your requirements, so that we might suggest better implementation methods. Otherwise follow @vinod answer. – Saeed Neamati Commented Jul 11, 2011 at 9:55
- Basically my requirement is that I have a text box and there can be any length of words and to select each word, I have to double click each word. Doing single click just puts the cursor in it. So I wanted to trigger double click event whenever single click is done so that word gets selected where the cursor is pointed even in single click. Thanks! – kxhitiz Commented Jul 11, 2011 at 11:05
1 Answer
Reset to default 1The code you provided above works for me. A double click is triggered when a single click occurs. I used this variation:
var numd = 0;
$("#content").dblclick(function() {
numd++;
});
$("#content").click(function() {
$(this).dblclick();
});
numd
is incremented correctly.
For multiple clicks:
You could use a variable to keep track of which click you are on while using the click()
method to perform clicks. Here is an example to trigger a triple click.
var clicknum = 0;
$("#text-box").click(function() {
clicknum++;
if (clicknum < 3) {
$(this).click();
}
else {
// Reset clicknum since we're done.
clicknum = 0;
}
}
本文标签: Triggering double click via jQuery or pure Javascript for a single click eventStack Overflow
版权声明:本文标题:Triggering double click via jQuery or pure Javascript for a single click event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745412960a2657551.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论