经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » JS/JS库/框架 » jQuery » 查看文章
JQuery 实现多个checkbox 只选中一个
来源:cnblogs  作者:?Geovin Du Dream Park?  时间:2019/5/13 8:56:47  对本文有异议
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  5. <meta name = "viewport" content = "user-scalable=no, width=device-width">
  6. <meta name="apple-mobile-web-app-capable" content="yes" />
  7. <title>JQuery 实现多个checkbox 只选中一个</title>
  8. <meta name="author" content="geovindu,塗聚文,Geovin Du" />
  9. <script src="Scripts/jquery.min.js" type="text/javascript"></script>
  10.  
  11. </head>
  12.  
  13. <body>
  14. <script type="text/javascript">
  15. $(function() {
  16. $('#common-form').find('input[type=checkbox]').bind('click', function(){
  17. var id = $(this).attr("id");
  18. //当前的checkbox是否选中
  19. if(this.checked){
  20. //除当前的checkbox其他的都不选中
  21. $("#common-form").find('input[type=checkbox]').not(this).attr("checked", false);
  22. //选中的checkbox数量
  23. var selectleng = $("input[type='checkbox']:checked").length;
  24. console.log("选中的checkbox数量"+selectleng); }
  25. else{
  26. //未选中的处理
  27. console.log("未选中的处理");
  28. }
  29. });
  30. })
  31. //http://9bitstudios.github.io/flexisel/
  32. //https://github.com/9bitStudios/flexisel/
  33. </script>
  34.  
  35. <form id="common-form">
  36. <input name="H1" type="checkbox"/>check1
  37. <input name="H2" type="checkbox"/>check2
  38. <input name="H3" type="checkbox"/>check3
  39. </form>
  40. <form id="form1" name="form1" class="form1" method="post" action="SaveReQuestTickets.aspx?Action=Add&ProjectID=23">
  41. <input name="H1" type="checkbox" id="H1" value="1"/>check1
  42. <input name="H2" type="checkbox" id="H2" value="2"/>check2
  43. <input name="H3" type="checkbox" id="H3" value="3"/>check3
  44. </form>
  45. <script type="text/javascript">
  46. $(function() { $("#form1").find('input[type=checkbox]').bind('click', function(){
  47. var id = $(this).attr("id"); //当前的checkbox是否选中
  48. if(this.checked){ //除当前的checkbox其他的都不选中
  49. $("#form1").find('input[type=checkbox]').not(this).attr("checked", false); //选中的checkbox数量
  50. var selectleng = $("input[type='checkbox']:checked").length;
  51. console.log("选中的checkbox数量"+selectleng);
  52. }
  53. else
  54. { //未选中的处理
  55. console.log("未选中的处理");
  56. }
  57. });
  58. })
  59. </script>
  60. </body>
  61.  
  62. </html>

  

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  5. <meta name = "viewport" content = "user-scalable=no, width=device-width">
  6. <meta name="apple-mobile-web-app-capable" content="yes" />
  7. <title>Flexisel - A responsive jQuery Carousel</title>
  8. <meta name="author" content="geovindu,塗聚文,Geovin Du" />
  9. <link href="css/style.css" rel="stylesheet" type="text/css" />
  10. <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
  11. <script type="text/javascript" src="js/jquery.flexisel.js"></script>
  12.  
  13. </head>
  14.  
  15. <body>
  16.  
  17. <h1>Flexisel</h1>
  18.  
  19. <p>Flexisel will adapt responsively as the screen width gets smaller...</p>
  20.  
  21. <ul id="flexiselDemo1">
  22. <li><img src="images/logo-nyt.png" /></li>
  23. <li><img src="images/logo-microsoft.png" /></li>
  24. <li><img src="images/logo-ebay.png" /></li>
  25. <li><img src="images/logo-hp.png" /></li>
  26. <li><img src="images/logo-youtube.png" /></li>
  27. </ul>
  28. <div class="clearout"></div>
  29.  
  30. <p>You can also change the number of items shown depending on the screen width.</p>
  31.  
  32. <ul id="flexiselDemo2">
  33. <li><img src="images/logo-adidas.png" /></li>
  34. <li><img src="images/logo-nike.png" /></li>
  35. <li><img src="images/logo-amazon.png" /></li>
  36. <li><img src="images/logo-spotify.png" /></li>
  37. <li><img src="images/logo-android.png" /></li>
  38. </ul>
  39. <div class="clearout"></div>
  40. <p>Other options include autoplay, number of items to scroll, animation speed when scrolling right and left, initial number of visible items, and more!</p>
  41. <ul id="flexiselDemo3">
  42. <li><img src="images/1.jpg" /></li>
  43. <li><img src="images/2.jpg" /></li>
  44. <li><img src="images/3.jpg" /></li>
  45. <li><img src="images/4.jpg" /></li>
  46. </ul>
  47.  
  48. <div class="clearout"></div>
  49.  
  50. <p>And you can set whether you want the slider to be infinite or not.</p>
  51.  
  52. <ul id="flexiselDemo4">
  53. <li><img src="images/chevrolet.png" /></li>
  54. <li><img src="images/ford.png" /></li>
  55. <li><img src="images/aston-martin.png" /></li>
  56. <li><img src="images/mini.png" /></li>
  57. <li><img src="images/lamborghini.png" /></li>
  58. <li><img src="images/ferrari.png" /></li>
  59. </ul>
  60.  
  61. <script type="text/javascript">
  62. //http://9bitstudios.github.io/flexisel/
  63. //https://github.com/9bitStudios/flexisel/
  64.  
  65. $(window).load(function() {
  66. $("#flexiselDemo1").flexisel();
  67.  
  68. $("#flexiselDemo2").flexisel({
  69. visibleItems: 4,
  70. itemsToScroll: 3,
  71. animationSpeed: 200,
  72. infinite: true,
  73. navigationTargetSelector: null,
  74. autoPlay: {
  75. enable: true,
  76. interval: 5000,
  77. pauseOnHover: true
  78. },
  79. responsiveBreakpoints: {
  80. portrait: {
  81. changePoint:480,
  82. visibleItems: 1,
  83. itemsToScroll: 1
  84. },
  85. landscape: {
  86. changePoint:640,
  87. visibleItems: 2,
  88. itemsToScroll: 2
  89. },
  90. tablet: {
  91. changePoint:768,
  92. visibleItems: 3,
  93. itemsToScroll: 3
  94. }
  95. },
  96. loaded: function(object) {
  97. console.log('Slider loaded...');
  98. },
  99. before: function(object){
  100. console.log('Before transition...');
  101. },
  102. after: function(object) {
  103. console.log('After transition...');
  104. },
  105. resize: function(object){
  106. console.log('After resize...');
  107. }
  108. });
  109. $("#flexiselDemo3").flexisel({
  110. visibleItems: 5, //显示多少个图片
  111. itemsToScroll: 1,
  112. animationSpeed: 400,
  113. infinite: true,
  114. navigationTargetSelector: null,
  115. autoPlay: {
  116. enable: true,
  117. interval: 5000,
  118. pauseOnHover: true
  119. },
  120. responsiveBreakpoints: {
  121. portrait: {
  122. changePoint:480,
  123. visibleItems: 1,
  124. itemsToScroll: 1
  125. },
  126. landscape: {
  127. changePoint:640,
  128. visibleItems: 2,
  129. itemsToScroll: 2
  130. },
  131. tablet: {
  132. changePoint:768,
  133. visibleItems: 3,
  134. itemsToScroll: 3
  135. }
  136. }
  137. });
  138. $("#flexiselDemo4").flexisel({
  139. infinite: false
  140. });
  141. });
  142. </script>
  143. </body>
  144. </html>

  

原文链接:http://www.cnblogs.com/geovindu/p/10844379.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号