81,122
社区成员




<body>
<form name="form1" method="post" action="myb.jsp">
<input type="button" name="1" id="1" value="1" onclick="getvalue(this,'h1')"/>
<input type="button" name="2" id="2" value="2" onclick="getvalue(this,'h2')"/>
<input type="button" name="2" id="3" value="3" onclick="getvalue(this,'h3')"/>
<input type="submit" name="=" id="="/>
<input type="hidden" name="h1" id="h1" value="4"/>
<input type="hidden" name="h2" id="h2" value="5"/>
<input type="hidden" name="h3" id="h3" value="6"/>
<script>
var count=1;
function getvalue(btn){
document.getElementById("h"+count).value=btn.value;
alert(document.getElementById("h"+count).value);
count++;
if(count==4){
count=1;
}
}
</script>
</form>
</body>
好像明白你要的效果了,改了下,如果点了3次后又重新从第1次开始,看看是不是这样
<body>
<form name="form1" method="post" action="myb.jsp">
<input type="button" name="1" id="1" value="1" onclick="getvalue(this,'h1')"/>
<input type="button" name="2" id="2" value="2" onclick="getvalue(this,'h2')"/>
<input type="button" name="2" id="3" value="3" onclick="getvalue(this,'h3')"/>
<input type="submit" name="=" id="="/>
<input type="hidden" name="h1" id="h1" value="4"/>
<input type="hidden" name="h2" id="h2" value="5"/>
<input type="hidden" name="h3" id="h3" value="6"/>
<script>
function getvalue(btn,h){
document.getElementById(h).value=btn.value;
alert(document.getElementById(h).value);
}
</script>
</form>
</body>
稍微改了下,纯js的,JS熟悉了可以学学jquery,比较流行