日期:2014-05-17  浏览次数:20965 次

关于如何动态获取button的value值
怎么实现让h1的value值等于第一个被点的按钮
        让h2的value值等于第二个被点的按钮
        让h3的value值等于第三个被点的按钮的getvalue()函数可以加参数。。初学者。。不会


<body>
<form name="form1" method="post" action="myb.jsp">
<input type="button" name="1" id="1" value="1" onclick="getvalue()"/>
<input type="button" name="2" id="2" value="2" onclick="getvalue()"/>
<input type="button" name="2" id="3" value="3" onclick="getvalue()"/>
<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){



}
</script>
</form>
</body>
web开发 value?button

------解决方案--------------------

<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次开始,看看是不是这样
------解决方案--------------------
看得有点晕,不过看懂了
------解决方案--------------------
总体思路就是用javascript,先获取到form,在获取到form里面的button,在获取到button上面的按钮,javascript获取页面值这样的思路最基础,还有就是使用id或者name,多试试就ok了,祝福你,