由于手机设备点击有200毫秒的延迟,会导致点击出问题,于是我们引入fastclick.js
1,引入库文件fastclick.js
2,注入事件进去(body或者某个元素)
3,若使用jQuery
$(function() { FastClick.attach(document.body); });//可将本文本直接写入fastclick.js最后
4,一个demo
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>fastclick说明书</title> <script src="fastclick.js"></script> </head> <body> <button id="click">click me!</button> <script type="text/javascript"> if ('addEventListener' in document) { document.addEventListener('DOMContentLoaded', function(){ FastClick.attach(document.body); }, false); } document.querySelector("#click").addEventListener("click",function(){ alert("click me!"); },false) </script> </body> </html>