日期:2014-05-16 浏览次数:20471 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
var array = [];//变量问题你把它在函数外面定义就行了
function test() {
id = parseInt(document.getElementById('txt_one').value);
k = 0;
alert("id是" + id);
switch (k) {
case 0:
array[id] = id;
break;
}
for (var i = 0; i < array.length; i++) {
alert("数组的长度为" + array.length);
alert(array[i]);
}
}
</script>
</head>
<body>
<input type="text" id="txt_one" value="0"/>
<input type="button" id="btn_one" value="点击" onclick="test()"/>
</body>
</html>