jQuery操作radio、checkbox、select示例

<script src= "../jquery-1.11.1.min.js" ></script>//引入jQuery插件
 
<input type= "radio" name= "radio" id= "radio1" value= "1" />1   
<input type= "radio" name= "radio" id= "radio2" value= "2" />2   
<input type= "radio" name= "radio" id= "radio3" value= "3" />3   
<input type= "radio" name= "radio" id= "radio4" value= "4" />4  
 
<br/>
 
<input type= "checkbox" name= "checkbox" id= "checkbox_id1" value= "1" />1   
<input type= "checkbox" name= "checkbox" id= "checkbox_id2" value= "2" />2   
<input type= "checkbox" name= "checkbox" id= "checkbox_id3" value= "3" />3   
<input type= "checkbox" name= "checkbox" id= "checkbox_id4" value= "4" />4   
<input type= "checkbox" name= "checkbox" id= "checkbox_id5" value= "5" />5   
 
<br/>
 
<select name= "select" id= "select_id" style= "width: 100px;" >   
     <option value= "1" >1</option>   
     <option value= "2" >2</option>   
     <option value= "3" >3</option>   
     <option value= "4" >4</option>   
     <option value= "5" >5</option>   
     <option value= "6" >6</option>   
</select>  
 
<br/>
 
<span onclick= "show()" >点击</span>
 
<script  type="text/javascript">
 
function show()
{
     //jquery获取单选框的值
     alert($( ‘input[type="radio"][name="radio"]:checked‘ ).val());
 
     //jquery循环输出选中的值
     $( "input[type=checkbox][name=checkbox]:checked" ).each( function (){
         alert($( this ).val());   
     });   
 
     //jquery获取Select选中项的Value   
     alert($( "#select_id" ).val());
 
     //jquery获取Select选中项的Text              
     alert($( "#select_id :selected" ).text());   
}
 
</script>


jQuery操作radio、checkbox、select示例,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。