添加双击事件

Add double click event

我实现了spectrum color picker, and I am trying to add a double click event to the palettes. (The one that has the predefined colors, the class name is: sp-thumb-el.) I added the following code after line 476:

paletteContainer.on("dblclick", ".sp-thumb-el", function (){
    console.log("you Double Clicked");
});

双击时没有任何反应。我做错了什么,我该如何解决?

Line 479 in JSFiddle

我想你想做这样的事情。

$("#btn").dblclick(function(){

  console.log("working fine");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="btn" > double click it </button>

看来你错过了 https://bgrins.github.io/spectrum/spectrum.js
此外,您需要删除 spectrum.css link 并在 https://bgrins.github.io/spectrum/spectrum.css

添加正确的 https 版本

查看更新版本@https://jsfiddle.net/f72tscdj/

希望这对您有所帮助, 肖恩

关于我上面的评论,您可能想尝试这样的破解:

       paletteContainer.on("click", ".sp-thumb-el", function (e){
            e.preventDefault();
            e.stopImmediatePropagation();
                            clicks++;
           if(clicks===2){
             console.log("you Double Clicked");
             clicks=0;
           } 
        });

你的 plunkr 中也更新了同样的内容..