js設定單選框選中,取消
阿新 • • 發佈:2019-01-01
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Insert title here</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="content-type" content="text/html; charset=UTF-8"> <script src="js/jquery-1.8.2.js"></script> </head> <body> <div style="width: 90%;height: 20px;padding-left: 5%;"> <label>測試</label> <input type="checkbox" id="testCheckbox"> </div> <button style="margin: 10px 40%;width: 100px;">測試</button> </body> <script type="text/javascript"> (function(){ $("button").on("click",function(){ var flag = $("#testCheckbox").is(":checked"); if(flag){ $("#testCheckbox").prop("checked",0); }else{ $("#testCheckbox").prop("checked",1); } }); })(); </script> </html>