html
<input type='checkbox' οnclick='selectCheckbox(this);' name='selectCheckbox' id="10001" value="大明">
<input type='checkbox' οnclick='selectCheckbox(this);' name='selectCheckbox' id="10002" value="二明">
<input type='checkbox' οnclick='selectCheckbox(this);' name='selectCheckbox' id="10003" value="三明">
<input type='checkbox' οnclick='selectCheckbox(this);' name='selectCheckbox' id="10004" value="四明">
<input type='checkbox' οnclick='selectCheckbox(this);' name='selectCheckbox' id="10005" value="小明">
ID :<input type='checkbox' id="userId">
姓名:<input type='checkbox' id="userName">
js
//
function selectCheckbox(obj){
//单选
if($(obj).is(":checked")){
//给所有name为selectCheckbox的input框设置为未选中状态
$("input[name='selectCheckbox']").prop("checked",false);
//给当前input框设置为选中状态
$(obj).prop("checked",true);
//给画面赋值
$("#userId").val($(obj).attr("id"));
$("#userName").val($(obj).val());
}
}
<input type='checkbox' οnclick='selectCheckbox(this);' name='selectCheckbox' id="10001" value="大明">
<input type='checkbox' οnclick='selectCheckbox(this);' name='selectCheckbox' id="10002" value="二明">
<input type='checkbox' οnclick='selectCheckbox(this);' name='selectCheckbox' id="10003" value="三明">
<input type='checkbox' οnclick='selectCheckbox(this);' name='selectCheckbox' id="10004" value="四明">
<input type='checkbox' οnclick='selectCheckbox(this);' name='selectCheckbox' id="10005" value="小明">
ID :<input type='checkbox' id="userId">
姓名:<input type='checkbox' id="userName">
js
//
function selectCheckbox(obj){
//单选
if($(obj).is(":checked")){
//给所有name为selectCheckbox的input框设置为未选中状态
$("input[name='selectCheckbox']").prop("checked",false);
//给当前input框设置为选中状态
$(obj).prop("checked",true);
//给画面赋值
$("#userId").val($(obj).attr("id"));
$("#userName").val($(obj).val());
}
}