checkbox改写

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
 
</body>
</html><!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" charset="utf-8"/>
<script src="js/jquery-3.2.1.min.js"></script>
</head>
<body>
<input type="checkbox" id="one" value="1" onClick="checkBox(this);"/><label for="">1</label><br />
<input type="checkbox" id="two" value="2" onClick="checkBox(this);"/><label for="">2</label><br />
<input type="checkbox" id="three" value="3" onClick="checkBox(this);"/><label for="">3</label><br />
<input type="checkbox" id="four" value="4" onClick="checkBox(this);"/><label for="">4</label><br />
<div id="content-area"></div><br />
 
</body>
<script type="text/javascript">
//the main function
function checkBox(obj) {
var this_area = document.getElementById("content-area");
this_id = obj.id;
this_unit = document.getElementById(this_id);
this_value = obj.value;
var realTime_area = "";
 
console.info(typeof this_value)
 
var Input_value = ['1', '2', '3', '4',]
console.info(this_unit.checked)
console.info(this_id)
if (this_unit.checked) {
var para = document.createElement("div");
para.style.display = "inline-block";
if (Input_value.indexOf(this_value) >= 0 && this_value !== '2') {
area = '<div style="width:30px;height:30px;background: pink" id="' + this_id + "1" + '"></div><lable>' + this_value + '</lable>'
para.innerHTML = area;
this_area.appendChild(para);
} else if (this_value === "2") {
console.info("----------2")
area = '<div style="width:30px;height:30px;background: green" id="' + this_id + "1" + '"></div><lable>' + this_value + '</lable>'
para.innerHTML = area;
this_area.appendChild(para);
}
}else{
real_this_id = this_id + "1";
real_this1 = document.getElementById(real_this_id);
$("#" + real_this_id).parent().remove();
}
}
</script>
</html>
posted @ 2019-06-12 22:02  小丸子姐姐  阅读(115)  评论(0编辑  收藏  举报