<p> <input type="text" name="T1" size="20"><input type="button" value="+" onclick="addit(this)"/><input type="button" value="-" onclick="subit(this)"/> </p>
<p> <input type="text" name="T1" size="20"><input type="button" value="+" onclick="addit(this)"/><input type="button" value="-" onclick="subit(this)"/> </p>
<p> <input type="text" name="T1" size="20"><input type="button" value="+" onclick="addit(this)"/><input type="button" value="-" onclick="subit(this)"/> </p>
<script defer>
function addit(o)
{
o.previousSibling.value=parseInt(o.previousSibling.value)+1;
}
function subit(o)
{
o.previousSibling.previousSibling.value=parseInt(o.previousSibling.previousSibling.value)-1;
}
</script>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script>
function add(obj){
var p =obj.parentElement;
var t =p.getElementsByTagName("input")[0];
t.value = t.value*1 +1;
}
function min(obj){
var p =obj.parentElement;
var t =p.getElementsByTagName("input")[0];
t.value = t.value*1 -1;
}
</script>
</HEAD> <BODY>
<p> <input type="text" name="T1" size="20" value="0">
<input type="button" width=50px value="+" onclick="add(this)">
<input type="button" width=50px value="-" onclick="min(this)"></p>
<p> <input type="text" name="T1" size="20" value="0">
<input type="button" width=50px value="+" onclick="add(this)">
<input type="button" width=50px value="-" onclick="min(this)"></p>
<p> <input type="text" name="T1" size="20" value="0">
<input type="button" width=50px value="+" onclick="add(this)">
<input type="button" width=50px value="-" onclick="min(this)"></p> </BODY>
</HTML>
<input type="text" name="T1" size="20" value="1"><input type="button" value="+" /><input type="button" value="-" /><br />
<input type="text" name="T1" size="20" value="2"><input type="button" value="+" /><input type="button" value="-" /><br />
<input type="text" name="T1" size="20" value="3"><input type="button" value="+" /><input type="button" value="-" /><br />
<script defer>
var buttonaddall = document.getElementsByTagName("input");
for (i=0;i<buttonaddall.length;i++){
(function(i){
if (buttonaddall[i].type=="button" && buttonaddall[i].value == "+"){
buttonaddall[i].onclick=function(){
buttonaddall[i].previousSibling.value = parseInt(buttonaddall[i].previousSibling.value) + 1;
}
}
else if (buttonaddall[i].type=="button" && buttonaddall[i].value == "-"){
buttonaddall[i].onclick=function(){
buttonaddall[i].previousSibling.previousSibling.value=parseInt(buttonaddall[i].previousSibling.previousSibling.value)-1;
}
}
})(i)
}
</script>
我觉得前台代码应该尽量行为与表现分离