标签:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style type="text/css"> .btn1 { width:200px; height:50px; background -color:gary; } </style> <script type="text/javascript"> window.onload = function () { var aBtn = document.getElementsByTagName("input"); for (var i = 0; i < aBtn.length; i++) { aBtn[i].index = i; aBtn[i].onclick = function() { alert(aBtn[this.index].value); } } }; </script> </head> <body> <input type="button" class = "btn1" value="aaaa" id="btn2"/> <input type="button" class = "btn1" value="bbbb" id="btn3"/> </body> </html>
点击事件index的用处,经常会出错。。
标签:
原文地址:http://www.cnblogs.com/pcd12321/p/4868346.html