标签:
(jquery)需要自己添加
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>js模拟jq的点击效果</title> <style> * {margin: 0; padding: 0;} #btn {display:block;height: 30px; width: 100px;margin: 100px auto 0;} </style> </head> <body> <button id="btn">点击</button> <script> (function(){ function $(targetID) { var word = targetID.substring(0,1); if (word == ‘#‘) { var ID = targetID.replace(/#/g,‘‘); var obj = document.getElementById(ID); obj.click = function(fn) { this.onclick = fn; } return obj; } } window.jQuery = $; window.$ = window.jQuery; })(); $(‘#btn‘).click(function() { alert(‘qqq‘); }); </script> </body> </html>
标签:
原文地址:http://www.cnblogs.com/handsomehan/p/5893848.html