百度首页 | 百度空间
 
查看文章
 
JavaScript闭包
2008年07月18日 星期五 下午 01:34

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>

<body>
<input type="button" value="Button1" id="button_1">
<input type="button" value="Button2" id="button_2">
<input type="button" value="Button3" id="button_3">
<script>
function abc() {
var aArr = new Array('button_1', 'button_2', 'button_3');
    for (var i=0; i<3; i++) {
        with({i:i})
                document.getElementById(aArr[i]).onclick= function () {
                    alert('当前你点击的是button_'+(i+1));
                }
    }
}
abc();
</script>
</body>
</html>


类别:代码 | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码:
 

     

©2008 Baidu