如何使用javascript显示或隐藏按钮单击上的div

问题描述:

以下是代码

here the following are the codes

<style type="text/css">
#mydiv{ margin:0 auto;padding:0;width:250px;height:100px; border:1px solid threedshadow;display:none;}
</style>

<script type="text/javascript">
function show()
{
var div=document.getElementById('mydiv');
div.style.display == "none" ? "block" : "none";
}
</script>



<input type="button" onclick="show()" value="show"/>
<div id="mydiv">

这段代码无法运作,任何人都可以帮助我!!

this code does not working can anybody help me!!

关闭,但是您没有将显示值分配给display属性。试试这个:

Close, but you're not assigning the display value to the display property. Try this:

div.style.display = (div.style.display == "none") ? "block" : "none";