当用户使用javascript函数单击时显示div
当用户单击按钮时,我需要在网页上显示一个div。 有人知道怎么做吗 到目前为止,我的代码是:当用户使用javascript函数单击时显示div,javascript,xhtml,html,Javascript,Xhtml,Html,当用户单击按钮时,我需要在网页上显示一个div。 有人知道怎么做吗 到目前为止,我的代码是: <body onload ="init()"> <input type="button" value="Display the div tree" onclick="check();" /> <script ="text/javascript"> function check() { // I'd like to d
<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>
函数检查(){
//我想在页面上显示div树
}
//我不想显示它,除非用户单击“显示div树”按钮
谢谢
布鲁诺我不确定自己是否理解了这个问题,这似乎有点太简单了:
function check() {
document.getElementById('tree').style.display=''; // or display='block';
}
编辑:这件事对你不起作用的原因是你的代码中有一个错误。请更改此行:
<script ="text/javascript">
到
一切都会好起来的。此外,您应该将脚本放在文档的标题中,但这不是绝对必要的
document.getElementById('tree').style.display='';
在您的检查功能中包括这一点@Bruno-只需尝试将您的脚本放在页面顶部,周围环绕着
=>您的div
之间是否有一个内容可以告诉您它是显示的,而不仅仅是
?
document.getElementById('tree').style.display='';