如何使用javascript显示或隐藏按钮单击上的div [英] how to show or hide a div on button click using javascript

查看:88
本文介绍了如何使用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";

这篇关于如何使用javascript显示或隐藏按钮单击上的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆