Javascript - CSS,点击可见性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14097018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript - CSS, visibility onclick
提问by Pete_1
I am very new to Javascript. I have been looking into using Javascript to edit css style properties. I have searched the web and looked at a lot of different problems. Even with all of that, it is probably my inexperience as to why I can't figure out what is wrong with my code. What adds to the problem is that there are so many ways to do this. Anyway here are the specifics.
我对 Javascript 很陌生。我一直在研究使用 Javascript 来编辑 css 样式属性。我在网上搜索并查看了很多不同的问题。即使有所有这些,可能是我的经验不足,为什么我无法弄清楚我的代码有什么问题。更糟糕的是,有很多方法可以做到这一点。无论如何,这里是具体的。
What I want it to do:When someone clicks on the link in the code, I want the hidden DIV (which will just be near the top of my waiting to be called on) to have its visibility switched to visible so as to create a new layer on the page.
我想要它做什么:当有人点击代码中的链接时,我希望隐藏的 DIV(它就在我等待被调用的顶部附近)将其可见性切换为可见,以便创建一个页面上的新图层。
My code:
我的代码:
<html>
<head>
<script language="javascript">
function newwindow() {
var showme = document.getelementbyid("testing");
showme.style.visibility = "visible";
}
</script>
</head>
<body>
<a href="#" onclick="newwindow()">Show me my hidden layer</a>
<div id="testing" style="position: absolute; visibility: hidden; left: 50%; top: 50%;
border: 1px solid darkblue; width: 400px; height: 300px; line-height: 300px;
text-align: center; vertical-align: middle;
margin-top: -150px; margin-left: -200px; background: lightgray">HELLO!!!</div>
</body>
</html>
Now, I know there are a lot of ways to do this. But can someone show me what to tweak in the code I gave to make the way I am writing this work? Thanks so much for your time.
现在,我知道有很多方法可以做到这一点。但是有人可以告诉我在我提供的代码中进行哪些调整以实现我编写这项工作的方式吗?非常感谢您的时间。
回答by Pranav ?
It is document.getElementByIdnot document.getelementbyid
它document.getElementById不是document.getelementbyid
回答by Manish Nagar
use this code
使用此代码
<html>
<head>
<script language="javascript">
function newwindow() {
var showme = document.getElementById("testing");
showme.style.visibility = "visible";
}
</script>
</head>
<body>
<a href="#" onclick="newwindow()">Show me my hidden layer</a>
<div id="testing" style="position: absolute; visibility: hidden; left: 50%; top: 50%;
border: 1px solid darkblue; width: 400px; height: 300px; line-height: 300px;
text-align: center; vertical-align: middle;
margin-top: -150px; margin-left: -200px; background: lightgray">HELLO!!!</div>
</body>
</html>

