<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery-1.12.0.min.js" ></script>
<style type="text/css">
.box{
width: 300px;
height: 300px;
background: yellow;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$("#button").click(function(){
//获得复选框的选择状态
var value = $("#key1").is(":checked");
if(value){
//把选择值改为true
$("#key2").attr("checked",true);
}else{
//把选择值改为false
$("#key2").attr("checked",false);
}
//使用post方法上传
$.post(url,{key1:value},function(data,status){
//data返回的数据,status请求状态
});
//把结果打印出来
console.log(value);
});
});
</script>
</head>
<body>
<div class="box">
<form action="http://127.0.0.1:8020/TestProject/test1.html" method="post">
<input type="checkbox" name="key1" value="yes" id="key1"/>
<input type="checkbox" name="key1" value="yes" id="key2"/>
<input type="button" id="button" value="Click"/>
</form>
</div>
</body>
</html>
web复选框的基础用法
最新推荐文章于 2021-12-05 19:49:45 发布