The example in this article describes how to implement JavaScript to make the relevant input box gray and unavailable after the check box is selected. Share it with everyone for your reference. The details are as follows:
This function is often seen on some websites. If you select the check box, the relevant options will be grayed out and unavailable. It will look more professional and is also a way to improve the user experience.
The operation effect is as shown below:
The specific code is as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>选中复选框,相关类变灰</title> <script language="JavaScript"> <!-- function selectKind(the){ var obj = the; var container = document.getElementById("kind_" + obj.name); for(var i=0;i<container.getElementsByTagName("input").length;i++) { container.getElementsByTagName("input")[i].disabled = obj.checked; } } //--> </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head> <body> <input type='checkbox' value="2" name=aa onclick="selectKind(this)">我从事游戏编程 <div id="kind_aa"> <input type='checkbox' value="php" name=aa>PHP <input type='checkbox' value="asp.net" name=aa>ASP.NET <input type='checkbox' value="java" name=aa>JAVA </div> <input type='checkbox' value="1" name=bb onclick="selectKind(this)">平时不上网 <div id="kind_bb"> <input type='checkbox' value="baidu.com" name=bb>baidu.com <input type='checkbox' value="163.com" name=bb>163.com <input type='checkbox' value="jb51.net" name=bb>jb51.net </div> </body> </html>
I hope this article will be helpful to everyone’s JavaScript programming design.