jquery事件dblclick与click冲突的解决方法分享
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://apps.bdimg.com/libs/jquery/1.7.0/jquery.js"> </script> <script> $(document).ready(function(){ var timer = null; $('.button').live('click', function(event){ var self = $(this); timer && clearTimeout(timer); timer = setTimeout(function(){ console.log(self); },300); }).live('dblclick', function(event){ timer && clearTimeout(timer); console.log(event.type); }); }); </script> </head> <body> <p>这是一个段落。</p> <button class='button'>点我!</button> <br><br> <p><b>注意:</b>live() 方法在 jQuery 版本 1.7 中被废弃,在版本 1.9 中被移除。请使用 on() 方法代替。</p> </body> </html>
给心灵一个纯净空间,让思想,情感,飞扬!