Heim > Artikel > Web-Frontend > 以下代码如何让DIV先隐藏_html/css_WEB-ITnose
这是一个在网上找到的通过Button控制DIV的显示与隐藏代码,如何让div先隐藏?
nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script language="javascript" type="text/javascript"> var flag=1; function $(id) { return document.getElementById(id); } function controlDIV() { if(flag==0) { $("my").style.visibility="hidden"; $("bt_display").value="显示"; flag=1; } else { $("my").style.visibility=""; $("bt_display").value="隐藏"; flag=0; } } </script> </head> <body> <input type="button" id="bt_display" value="显示" onclick="controlDIV()"/> <div id="my" style="visibility:hidden"> <input type="text" value="my DIV"/> </div> </body> </html>