JavaScript如何让复选框不可见
时间:2022-02-23 17:37
方法:1、使用一个div元素将复选框包裹;2、使用“document.getElementById("id值")”获取这个div元素节点;3、使用“div元素节点.style.display = "none";”语句让复选框不可见。 本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。 JavaScript让复选框不可见 让复选框不可见,也就是隐藏复选框。 而说到隐藏元素,就想到使用 实现代码: 【相关推荐:javascript学习教程】 以上就是JavaScript如何让复选框不可见的详细内容,更多请关注gxlsystem.com其它相关文章!display:none
,这要给元素添加该样式即可。<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div id="box">
爱好:<input type="checkbox" name="running" id="run">跑步
<input type="checkbox" name="running" id="read">阅读
<input type="checkbox" name="running" id="shop">购物
</div>
<br />
<button onclick="myFunction()">让复选框不可见</button>
<script>
function myFunction() {
var box = document.getElementById("box");
box.style.display = "none";
}
</script>
</body>
</html>