[英]Display a div when a user clicks using a javascript function
I need to display on a webpage a div when a user clicks on a button. 用户单击按钮时,我需要在网页上显示div。 Does someone know how to do it ?
有人知道怎么做吗?
My code so far : 到目前为止我的代码:
<body onload ="init()">
<input type="button" value="Display the div tree" onclick="check();" />
<script ="text/javascript">
function check() {
// I'd like to display on the page the div tree
}
</script>
<div id = "tree" style="display:none"> // I don't want to display it unless the user clicks on the button "Display the div tree"
</div>
</body>
thanks, 谢谢,
Bruno 布鲁诺
document.getElementById('tree').style.display='';
包括在您的检查功能中
i'm not sure if i understood the question, this seems a bit too easy: 我不确定我是否理解这个问题,这似乎有点容易:
function check() {
document.getElementById('tree').style.display=''; // or display='block';
}
EDIT : 编辑:
the reason this dooesn't work for you is an error in your code. 此操作对您不起作用的原因是代码中的错误。 please change this line:
请更改此行:
<script ="text/javascript">
to 至
<script type="text/javascript">
and everything wiill be fine. 一切都会好起来的。 also, you should place the script in the
head
of your document, but thats not absolutely neccessary. 同样,您应该将脚本放置在文档的
head
,但这并不是绝对必要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.