javascript批量注册事件处理函数代码实例
分类:实例代码
本章节分享一段代码实例,它实现了批量注册事件处理函数的功能。
代码实例如下:
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.pipipi.net/" /> <title>前端教程网</title> <script type="text/javascript"> window.onload = function () { var oBtn = document.getElementsByTagName('input'); var odiv = document.getElementById("antzone"); for (var index = 0; index < oBtn.length; ++index) { oBtn[index].abc = index; oBtn[index].onclick = function (e) { odiv.innerHTML = this.abc; }; }; }; </script> </head> <body> <input type="button" value="前端教程网一"/> <input type="button" value="前端教程网二"/> <input type="button" value="前端教程网三"/> <div id="antzone"></div> </body> </html>
javascript批量注册事件处理函数代码实例,这样的场景在实际项目中还是用的比较多的,关于javascript批量注册事件处理函数代码实例就介绍到这了。
javascript批量注册事件处理函数代码实例属于前端实例代码,有关更多实例代码大家可以查看。