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

如何用JS给隐藏域赋值?
我需要实现,单击表单中不同的单选按钮,将不同的值赋给隐藏域?代码如下
<input   type= "radio "   name= "operate "   value= "2 "   onclick= "taskstatus.value=2 "   />
<input   type= "radio "   name= "operate "   value= "3 "   />
<input   name= "taskstatus "   type= "hidden "   id= "taskstatus "   value= " "     />
但隐藏域的值总是初始的空值,如果将隐藏域换为文本框就可以赋值成功,急求解决!多谢

------解决方案--------------------
怎么会呢?写得没问题啊,你测试一下看看,赋值成功了,只是不知道你后面要怎么操作

<script>
function chkValue() {
var cfield=document.getElementById( 'taskstatus ');
alert(cfield.value);
}
</script>

<input type= "radio " name= "operate " value= "2 " onclick= "taskstatus.value=2 " />
<input type= "radio " name= "operate " value= "3 " onclick= "taskstatus.value=3 " />
<input name= "taskstatus " type= "hidden " id= "taskstatus "/>
<input type= "button " onclick= "chkValue(); " value= "check Value "/>