JQuery:单选框,复选框取值
<div style="width:100%; border:solid 1px #0000ff; line-height:25px">
<input type="radio" name="items" id="item1" value="1" checked="checked" />1
<input type="radio" name="items" id="item2" value="2"/>2
<input type="radio" name="items" id="item3" value="3"/>3
<input type="radio" name="items" id="item4" value="4"/>4
<input type="radio" name="items" id="item5" value="5"/>5
<br/>
<input id="bt_radio" type="button" value="单选框测试">
<script type="text/javascript">
$(document).ready(function(){
$("#bt_radio").click(function(){
alert($("input[@name=items][@checked]").val());
})
})
</script>
</div>
<br />
<div style="width:100%; border:solid 1px #0000ff; line-height:25px">
<input type="checkbox" name="cbType1" id="cbType1" value="1" checked/>1
<input type="checkbox" name="cbType1" id="cbType2" value="2" />2
<input type="checkbox" name="cbType1" id="cbType3" value="3" checked />3
<input type="checkbox" name="cbType1" id="cbType4" value="4" checked />4
<br/>
<input id="bt_checkbox" type="button" value="多选框测试">
<script type="text/javascript">
$(document).ready(function(){
$("#bt_checkbox").click(function(){
var aa="";
$("input[@name=cbType1][@checked]").each(function(){
aa+=$(this).val()+",";
})
alert(aa);
})
})
</script>
</div>
<br />
<div style="width:100%; border:solid 1px #0000ff; line-height:25px">
<input type="checkbox" name="cbType2" id="cbType21" value="1" checked/>1
<input type="checkbox" name="cbType2" id="cbType22" value="2" />2
<input type="checkbox" name="cbType2" id="cbType23" value="3" checked />3
<input type="checkbox" name="cbType2" id="cbType24" value="4" checked />4
<br/>
<input id="bt_checkbox2" type="button" value="多选框测试2">
<script type="text/javascript">
$(document).ready(function(){
$("#bt_checkbox2").click(function(){
var aa="";
$("input[@name=cbType2]").each(function(){
if(this.checked){
aa+=this.value+",";
}
})
alert(aa);
})
})
</script>
</div>
<input type="radio" name="items" id="item1" value="1" checked="checked" />1
<input type="radio" name="items" id="item2" value="2"/>2
<input type="radio" name="items" id="item3" value="3"/>3
<input type="radio" name="items" id="item4" value="4"/>4
<input type="radio" name="items" id="item5" value="5"/>5
<br/>
<input id="bt_radio" type="button" value="单选框测试">
<script type="text/javascript">
$(document).ready(function(){
$("#bt_radio").click(function(){
alert($("input[@name=items][@checked]").val());
})
})
</script>
</div>
<br />
<div style="width:100%; border:solid 1px #0000ff; line-height:25px">
<input type="checkbox" name="cbType1" id="cbType1" value="1" checked/>1
<input type="checkbox" name="cbType1" id="cbType2" value="2" />2
<input type="checkbox" name="cbType1" id="cbType3" value="3" checked />3
<input type="checkbox" name="cbType1" id="cbType4" value="4" checked />4
<br/>
<input id="bt_checkbox" type="button" value="多选框测试">
<script type="text/javascript">
$(document).ready(function(){
$("#bt_checkbox").click(function(){
var aa="";
$("input[@name=cbType1][@checked]").each(function(){
aa+=$(this).val()+",";
})
alert(aa);
})
})
</script>
</div>
<br />
<div style="width:100%; border:solid 1px #0000ff; line-height:25px">
<input type="checkbox" name="cbType2" id="cbType21" value="1" checked/>1
<input type="checkbox" name="cbType2" id="cbType22" value="2" />2
<input type="checkbox" name="cbType2" id="cbType23" value="3" checked />3
<input type="checkbox" name="cbType2" id="cbType24" value="4" checked />4
<br/>
<input id="bt_checkbox2" type="button" value="多选框测试2">
<script type="text/javascript">
$(document).ready(function(){
$("#bt_checkbox2").click(function(){
var aa="";
$("input[@name=cbType2]").each(function(){
if(this.checked){
aa+=this.value+",";
}
})
alert(aa);
})
})
</script>
</div>