您好我有以下2个
JavaScript函数来打开div并关闭它.
<script> function show() { if(document.getElementById('benefits').style.display=='none') { document.getElementById('benefits').style.display='block'; } } </script> <script> function close() { if(document.getElementById('benefits').style.display=='block') { document.getElementById('benefits').style.display='none'; } } </script>
这是html:
<div id="opener"><a href="#1" name="1" onclick=show()>click here</a></div> <div id="benefits" style="display:none;"> some input in here plus the close button <div id="upbutton"><a onclick=close()></a></div> </div>
解决方法
<script> function show() { if(document.getElementById('benefits').style.display=='none') { document.getElementById('benefits').style.display='block'; } return false; } function hide() { if(document.getElementById('benefits').style.display=='block') { document.getElementById('benefits').style.display='none'; } return false; } </script> <div id="opener"><a href="#1" name="1" onclick="return show();">click here</a></div> <div id="benefits" style="display:none;">some input in here plus the close button <div id="upbutton"><a onclick="return hide();">click here</a></div> </div>