JQuery为checkbox批量设置值
来源:互联网 发布:网络直播造娃在线播放 编辑:程序博客网 时间:2024/06/10 18:40
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script src="js/jquery-1.7.1.min.js"></script> <script type="text/javascript"> $(function () { $("#btn").click(function () { alert($(":radio[name=gender]:checked").val()); }); $("#btn1").click(function () { $(":radio[name=gender]").val(["女"]); //中括号不能省略 $(":checkbox").val(["排球","足球"]); //中括号不能省略 }); }); </script></head><body> <input type="radio" name="gender" value="男" />男<br /> <input type="radio" name="gender" value="女" />女<br /> <input type="radio" name="gender" value="保密" />保密<br /><hr /> <input type="checkbox" value="篮球" />篮球<br /> <input type="checkbox" value="排球" />排球<br /> <input type="checkbox" value="乒乓球" />乒乓球<br /> <input type="checkbox" value="足球" />足球<br /> <button id="btn">取值</button><button id="btn1">设值</button></body></html>