JQuery:单选框,复选框取值

<div style="width:100%; border:solid 1px #0000ff; line-height:25px">    
      
<input type="radio" name="items" id="item1" value="1" checked="checked" />1&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="radio" name="items" id="item2" value="2"/>2&nbsp;&nbsp;&nbsp;&nbsp;  
        <input type="radio" name="items" id="item3" value="3"/>3&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="radio" name="items" id="item4" value="4"/>4&nbsp;&nbsp;&nbsp;&nbsp;
        <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&nbsp;&nbsp;&nbsp;&nbsp;
<input type="checkbox" name="cbType1" id="cbType2" value="2" />2&nbsp;&nbsp;&nbsp;&nbsp;
<input type="checkbox" name="cbType1" id="cbType3" value="3" checked />3&nbsp;&nbsp;&nbsp;&nbsp;
<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&nbsp;&nbsp;&nbsp;&nbsp;
<input type="checkbox" name="cbType2" id="cbType22" value="2" />2&nbsp;&nbsp;&nbsp;&nbsp;
<input type="checkbox" name="cbType2" id="cbType23" value="3" checked />3&nbsp;&nbsp;&nbsp;&nbsp;
<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>
posted @ 2008-04-02 11:33  liy  阅读(6073)  评论(1编辑  收藏  举报