Blogger Information
Blog 67
fans 0
comment 2
visits 72047
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
jQuery判断checkbox复选框是否已选中
搁浅
Original
837 people have browsed it
  1. <input type="checkbox" name="fruit" value="apple" />苹果
  2. <input type="checkbox" name="fruit" value="orange" />橘子
  3. <input type="checkbox" name="fruit" value="banana" />香蕉
  4. <input type="checkbox" name="fruit" value="grape" />葡萄
  5. <button id="bt1">判断选中</button>
  6. <script>
  7. $(function (){
  8. $("#bt1").click(function (){
  9. var checkVal='';//查找已选的值
  10. $("input[name='fruit']:checkbox").each(function(){
  11. if($(this).prop('checked')){
  12. checkVal+=$(this).val()+',';
  13. }
  14. })
  15. console.log(checkVal);
  16. var flag=false;//判断是否选中值
  17. $("input[name='fruit']:checkbox").each(function(){
  18. if($(this).prop('checked')){
  19. flag=true;
  20. }
  21. })
  22. console.log(flag)
  23. if(flag){
  24. alert('有被选中');
  25. }else{
  26. alert('没有选中任何选项');
  27. }
  28. })
  29. })
  30. </script>
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post