87,910
社区成员
发帖
与我相关
我的任务
分享
<!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>Trees, trees, everywhere </title>
</head>
<body>
<input type="text" value="222" id="0" />
<input type="text" value="222" id="1" />
<input type="text" value="222" id="2" />
<input type="text" value="222" id="3" />
<input type="text" value="222" id="4" />
<input type="button" value="ClickMe" id="do" />
<SCRIPT LANGUAGE="JavaScript">
<!--
window.testArr = ["1-222-3","2-333-4","3-444-5","4-555-6","5-666-7"];
window.onload=function(){
document.getElementById("do").onclick=function(){
var inputs = document.getElementsByTagName("input");
var texts = [];
for(var i=0;i<inputs.length;i++){
if(inputs[i].type == "text"){
texts.push(inputs[i]);
}
}
for(var i=0;i<texts.length;i++){
cruId = texts[i].id;
tmp = window.testArr[cruId].split("-");
tmp[1] = texts[i].value;
window.testArr[cruId] = tmp.join("-");
alert[cruId];
}
alert(window.testArr);//弹出修改后的值
}
alert(window.testArr);//先弹出修改前的值
}
//-->
</SCRIPT>
</body>
</html>