本文介绍了单击和双击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够将单击和双击事件绑定到一段文本.我知道我可以使用

I want to be able to bind a single and double click event to a span of text. I know I can use

data-bind ="event: { dblclick: doSomething }

进行双击,但是我还需要能够在单击时执行其他功能.有什么建议吗?

for a double click, but I also need the ability to perform a different function on single click. Any suggestions?

推荐答案

首先,我完全不建议使用click绑定.相反,您应该使用jQuery中的"click""dblclick"处理程序:

First, I wouldn't recommend click binding at all. Instead you should use "click" and "dblclick" handlers from jQuery:

$(someParentElement).on('click', 'your span selector', function (event) {
    var myViewModelFragment = ko.dataFor(this);
    // your code here
});

$(someParentElement).on('dblclick', 'your span selector', function (event) {
    var myViewModelFragment = ko.dataFor(this);
    // your code here
});

编辑:另请参见 Niko的建议关于支持单击和双击.基本上,您应该手动计算点击次数并相应地调用不同的功能.我以为jQuery为您处理了这个问题,但是不幸的是,它没有.

see also Niko's suggestion regarding supporting both single and double clicks. Basically, you should count the number of clicks manually and call different functions accordingly. I assumed jQuery handles this for you but, unfortunately, it doesn't.

这篇关于单击和双击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 16:42