html:checkbox中本没有值,我要判断它是否被选中,如果选中把它的值设为1,没有选中把它的值设为0;
我的代码如下:
1.js
<script type="text/javascript">
function getValue()
{
var ischecked=document.getElementById("iseditable");
if(ischecked.checked==true)
{
document.getElementById("iseditable").value=1;
alert("***1***"+document.getElementById("iseditable").value);
}
else
{
document.getElementById("iseditable").value=0;
alert("***0***"+document.getElementById("iseditable").value);
}
}
</script>
2.html:checkbox
<tr>
<th>是否可编辑</th>
<td><html:checkbox property="dictIseditable" styleId="iseditable" onclick="getValue();" value="0"></html:checkbox></td>
<th> </th>
<td> </td>
</tr>
无论我选中与否数据库插入的时候始终是1。
实在不知道问题出在哪里,
请哪位指点迷经,
先谢了!
我的代码如下:
1.js
<script type="text/javascript">
function getValue()
{
var ischecked=document.getElementById("iseditable");
if(ischecked.checked==true)
{
document.getElementById("iseditable").value=1;
alert("***1***"+document.getElementById("iseditable").value);
}
else
{
document.getElementById("iseditable").value=0;
alert("***0***"+document.getElementById("iseditable").value);
}
}
</script>
2.html:checkbox
<tr>
<th>是否可编辑</th>
<td><html:checkbox property="dictIseditable" styleId="iseditable" onclick="getValue();" value="0"></html:checkbox></td>
<th> </th>
<td> </td>
</tr>
无论我选中与否数据库插入的时候始终是1。
实在不知道问题出在哪里,
请哪位指点迷经,
先谢了!
本文探讨了一个关于HTML中checkbox元素的值设置问题。当checkbox被选中时希望将其值设置为1,未选中时设置为0。然而,无论是否选中,值总是被设置为1。文章提供了具体的JavaScript代码实现及HTML结构。
265

被折叠的 条评论
为什么被折叠?



