这里使用java脚本来显示和隐藏DIV
<a onclick="document.getElementById('div_name2').style.display = '';
return false;"
href="" style="text-decoration:none;border-bottom:1px dotted blue;">
Show more...</a>
<br />
<div id="div_name2" style="display:none;margin:15px 15px 0px 15px;padding:5px;border:1px solid #aaa;">
This is more information placed in our hidden div.
When you click on the "hide" link this DIV area will disappear:
<a onclick="document.getElementById('div_name2').style.display = 'none';
return false;" href=""
style="text-decoration:none;border-bottom:1px dotted blue;">hide</a>
</div>
这是使用
的代码DIV
可见DIV
当我加载此页面时,div是隐藏的,我如何使div可见???
答案 0 :(得分:3)
试试这段代码:
<a onclick="document.getElementById('div_name2').style.display = 'block';
return false;"
href="" style="text-decoration:none;border-bottom:1px dotted blue;">
Show more...</a>
<br />
<div id="div_name2" style="display:block;margin:15px 15px 0px 15px;padding:5px;border:1px solid #aaa;">
This is more information placed in our hidden div.
When you click on the "hide" link this DIV area will disappear:
<a onclick="document.getElementById('div_name2').style.display = 'none';
return false;" href=""
style="text-decoration:none;border-bottom:1px dotted blue;">hide</a>
</div>
你应该给你的div提供属性“display:block”,以便在加载网站时显示它。现在,当您单击链接时,应将display设置为none以隐藏div_name2