Jquery 添听checkbox 是否选中
生活随笔
收集整理的這篇文章主要介紹了
Jquery 添听checkbox 是否选中
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>learn</title> </head> <body> <input type="checkbox" name="" id="test" onclick="changetest(this)" value="232"><script src="https://cdn.bootcss.com/jquery/1.10.0/jquery.min.js"> </script> <script> function changetest(obj){console.log($(obj).is(':checked')); } </script></body> </html>結果:選中 true ; 取消選中 false;
2.判斷JQUERY是否選中
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>JQuery 判斷checkbox是否選中,checkbox全選,獲取checkbox選中值</title> <script type="text/javascript" language="javascript" src="http://code.jquery.com/jquery-1.6.4.min.js" ></script> <script type="text/javascript"> $(function(){/*------------全選/全不選------------*/$('#check-all').click(function(){//判斷apple是否被選中var bischecked=$('#check-all').is(':checked');var colors=$('input[name="color"]');bischecked?colors.attr('checked',true):colors.attr('checked',false);});/*-------------獲取選中值-------------*/$('#btn_submit').click(function(){$('input[name="color"]:checked').each(function(){var scolor=$(this).val();alert(scolor);});return false;});}) </script> </head><body><input type="checkbox" id="check-all" /><label for="check-all">全選/全不選</label><br /><br /><input type="checkbox" id="red" name="color" value="red" /><label for="red">red</label><input type="checkbox" id="blue" name="color" value="blue" /><label for="blue">blue</label><input type="checkbox" id="yellow" name="color" value="yellow" /><label for="yellow">yellow</label><input type="checkbox" id="green" name="color" value="green" /><label for="green">green</label><br /><br /><input type="button" id="btn_submit" value="添加" /></body> </html>?
轉載于:https://my.oschina.net/u/2494575/blog/1797672
總結
以上是生活随笔為你收集整理的Jquery 添听checkbox 是否选中的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: shell脚本逻辑判断,文件目录属性判断
- 下一篇: Spring Boot下Druid连接池