读书人

复选框的单选效能及传值

发布时间: 2012-08-24 10:00:21 作者: rapoo

复选框的单选功能及传值

通过遍历得到多组checkbox ,

<Script Language="JScript">
function checkedThis(obj,cname){
// alert(obj);
var boxArray = document.getElementsByName(cname);

for(var i=0;i<=boxArray.length-1;i++){
if(boxArray[i]==obj && obj.checked){
boxArray[i].checked = true;
boxArray[i].value = true;

// boxArray[i].value = 1; 这样做,在往action传值的时候会出错的,值传不过去

}else{
boxArray[i].checked = false;
boxArray[i].value = false;

// boxArray[i].value = 0;

}
}
}
</Script>

<s:checkbox name="selectedSign" onclick="checkedThis(this,'selectedSign');"/>

一开始

对checkbox赋值,只能赋boolean类型的,不能赋其他类型的,

生成的代码如下:<input type="checkbox" name="selectedSign" value="true" id="searchDataAdmin_selectedSign" onclick="checkedThis(this,'selectedSign');"/>
<input type="hidden" name="__checkbox_selectedSign" value="true" />

将这个字段的值保存到数据库中,数据库中保存的是0(false)或者是1(true)

读书人网 >Web前端

热点推荐