随笔 - 2, 文章 - 10, 评论 - 0, 阅读 - 15283
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年5月 >
27 28 29 30 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
1 2 3 4 5 6 7

2008年9月27日

利用JQUERY实现获取选中的单选框和复选框的值,单选框就不多说了,很方便就能实现,我在前面一篇日志中也提到过了,

今天主要说的是复选框,如何获取同时选中项的值.:

  1. input type="checkbox" name="cbType1" id="cbType4" value="4" checked />4
  2. <br/>
  3. <input id="bt_checkbox" type="button" value="多选框测试">
  4. <script type="text/javascript">
  5. $(document).ready(function(){
  6.         $("#bt_checkbox").click(function(){
  7.                     var aa="";
  8.                     $("input[@name=cbType1][@checked]").each(function(){
  9.                                 aa+=$(this).val()+",";
  10.                     })
  11.                     alert(aa);
  12.         })
  13. })
  14. </script>           
  15. </div>
  16. <br />
  17. <div style="width:100%; border:solid 1px #0000ff; line-height:25px">
  18. <input type="checkbox" name="cbType2" id="cbType21" value="1" checked/>1&nbsp;&nbsp;&nbsp;&nbsp;
  19. <input type="checkbox" name="cbType2" id="cbType22" value="2" />2&nbsp;&nbsp;&nbsp;&nbsp;
  20. <input type="checkbox" name="cbType2" id="cbType23" value="3" checked />3&nbsp;&nbsp;&nbsp;&nbsp;
  21. <input type="checkbox" name="cbType2" id="cbType24" value="4" checked />4
  22. <br/>
  23. <input id="bt_checkbox2" type="button" value="多选框测试2">
  24. <script type="text/javascript">
  25. $(document).ready(function(){
  26.         $("#bt_checkbox2").click(function(){
  27.                     var aa="";
  28.                     $("input[@name=cbType2]").each(function(){
  29.                             if(this.checked){
  30.                                     aa+=this.value+",";
  31.                             }
  32.                     })
  33.                     alert(aa);
  34.         })
  35. })
  36. </script>
  37. </div>

本文出处:http://www.cnblogs.com/liydotnet/archive/2008/04/02/1134240.html

posted @ 2008-09-27 16:39 jiangxin 阅读(3496) 评论(0) 推荐(0)

摘要: jquery取得text,areatext,radio,checkbox,select的值,以及其他一些操作; 1.假如我们有如下页面 2.下面来看怎么取得FORM中的各种值等等; function get_form_value(){ /*获得TEXT.AREATEXT的值*/ var textval = $("#text_id... 阅读全文

posted @ 2008-09-27 16:35 jiangxin 阅读(3562) 评论(0) 推荐(0)

点击右上角即可分享
微信分享提示