Method: 1. Use a div element to wrap the check box; 2. Use "document.getElementById("id value")" to get the div element node; 3. Use "div element node.style. The display = "none";" statement makes the checkbox invisible.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
JavaScript makes the check box invisible
Make the check box invisible, that is, hide the check box.
When it comes to hidden elements, I think of using display:none
, which requires adding this style to the element.
Implementation code:
<!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>
[Related recommendations: javascript learning tutorial]
The above is the detailed content of How to make checkbox invisible with JavaScript. For more information, please follow other related articles on the PHP Chinese website!