首页 > Web开发 > 详细

jQuery操作radio、checkbox、select示例

时间:2014-07-29 16:15:19      阅读:334      评论:0      收藏:0      [点我收藏+]
<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示例,布布扣,bubuko.com

jQuery操作radio、checkbox、select示例

原文:http://my.oschina.net/u/1453975/blog/295713

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!