Home > Article > Web Front-end > js controls the display and hiding of TR_javascript skills
A piece of code shared below: Select the Yes button to display the text box for height and weight. Note: The ready method must reference the jquery library.
1.html Code
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <style type="text/css"> .div1{ width:300px; height:80px; border:1px solid green;} .div2{ width:300px; height:80px; border:1px solid red;} </style> <SCRIPT language=javascript type=text/javascript src="jquery-1.7.2.min.js"></SCRIPT> <script type="text/javascript"> function setDetailMsgRow(rowID,sel) { var row = document.getElementById(rowID); if (row != null) { if (sel.value == 1) { row.style.display = "block"; } else { row.style.display = "none"; } } } /*自动加载隐藏框,ready方法必须要引用jquery的库*/ $(document).ready(function(){ var sel = document.getElementById('selID'); setDetailMsgRow('show',sel); }); function onload() {var sel = document.getElementById('selID'); setDetailMsgRow('show',sel); } </script> </head> <body> <TABLE border="1" cellpadding="2" cellspacing="0"> <TBODY> <TR> <TD>是否填写身高体重</TD> <TD><SELECT width='100%' id=selID onchange = "setDetailMsgRow('show',this)"> <OPTION value="1" selected>是</OPTION> <OPTION value="0">否</OPTION> <OPTION ></OPTION> </SELECT> </TD><TD></TD><TD></TD></TR> <TR id=show style="display:none;"> <TD>身高</TD> <TD><INPUT id=Height></TD> <TD>体重</TD> <TD><INPUT id=Weight></TD></TR> </TBODY> </TABLE> </body> </html>
You can download jquery-1.7.2.min.js online and introduce it.
2. Effect
The above is the entire content of this article. I hope it will be helpful to everyone in learning javascript programming.