码迷,mamicode.com
首页 > 其他好文 > 详细

点击事件问题

时间:2015-10-10 23:04:25      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:

<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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!