實現(xiàn)的效果是共用一個頁面(添加和修改),默認為checkbox
添加為checkbox,修改為radio
前端頁面展示如下
<tr class="roleList">
<th>
管理角色:
</th>
<td>
<#assign roleSet = (admin.roleSet)! />
<#list allRoleList as role>
<label>
<input type="checkbox" name="roleList.id" id="rolest" value="${role.id}"<#if (roleSet.contains(role))!> checked</#if> />${role.name}
</label>
</#list>
<label class="requireField">*</label>
</td>
</tr>
function add(){
localStorage.isUpdate = "false";
location.href='team_data!add.action';
}
function update(){
var s = $("#infoMarket").datagrid('getSelections');
if(s == null || s == "") {
return $.messager.alert("提示", "必須選中一行");
} else if(s.length > 1) {
return $.messager.alert("提示", "操作錯誤,只能選中一行");
}
var keyid = $("#infoMarket").datagrid('getSelections')[0].keyid;
localStorage.isUpdate = "true";
location.href="team_data!edit.action?id="+keyid;
}
js控制
if(localStorage.isUpdate=="true"){
var id = document.getElementsByName('roleList.id');
var value = new Array();
for(var i = 0; i < id.length; i++){
id[i].type="radio";
}
}else{
var id = document.getElementsByName('roleList.id');
var value = new Array();
for(var i = 0; i < id.length; i++){
id[i].type="checkbox";
}
}
設置一個全局變量,點擊頁面通過修改type來控制復選框的狀態(tài)
獲取復選框的值
var id = document.getElementsByName('roleList.id');
var value="";
for(var i = 0; i < id.length; i++){
if(id[i].checked)
//value.push(id[i].value);
value+=id[i].value+",";
}
value=value.substring(0,value.length-1);