- radio 单选
- checkbox 多选
radio示例:
<label style="float:left;padding-left: 12px;"><input class="ace" name="resultState" id="form-field-radio0" checked="checked" type="radio" value="1"><span class="lbl">办结</span></label>
<label style="float:left;padding-left: 5px;"><input class="ace" name="resultState" id="form-field-radio1" type="radio" value="2"><span class="lbl">无法办理</span></label>
<label style="float:left;padding-left: 5px;" id="return"><input class="ace" name="resultState" id="form-field-radio3" type="radio" value="3"><span class="lbl">退回</span></label>
checkbox 多选:
<
input
type
=
"checkbox"
name
=
"test"
value
=
"1"
/><
span
>1</
span
><
input
type
=
"checkbox"
name
=
"test"
value
=
"2"
/><
span
>2</
span
><
input
type
=
"checkbox"
name
=
"test"
value
=
"3"
/><
span
>3</
span
><
input
type
=
"checkbox"
name
=
"test"
value
=
"4"
/><
span
>4</
span
><
input
type
=
"checkbox"
name
=
"test"
value
=
"5"
/><
span
>5</
span
><
input
type
=
'button'
value
=
'提交'
onclick
=
"show()"
/>
利用name属性值获取checkbox对象,然后循环判断checked属性(true表示被选中,false表示未选中)
javascript代码(jQuery):
function
show(){
obj = document.getElementsByName(
"test"
);
check_val = [];
for
(k
in
obj){
if
(obj[k].checked)
check_val.push(obj[k].value);
}
alert(check_val);
}