js设置单选框选中,取消

版权声明:本文为博主原创文章,转载请注明出处! https://blog.csdn.net/u012604299/article/details/80367609
<!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>

猜你喜欢

转载自blog.csdn.net/u012604299/article/details/80367609