2015-11-12 30 views
0

我正在处理某些事情,而现在我还没有任何代码,因为我不知道如何执行此操作!请帮我在这里:dJavaScript:将密码设置为spesefic div

我觉得这是很好的,如果我能有这样的改变我的风格密码:

<html> 
<head> 
<style> 
    .passwordProtected { 
     display:none; <- this is supposed to change to "block" when the password is written in, and they click "Show div" 
    } 
</style> 
</head> 
<body> 
    <div id="loginArea"> 
     <input type="password"> <--- This is where they type the password 
    </div> 
    <div id="passwordprotected" class="passwordProtected"> 
     <h1>This is the protected div they enter</h1> 
    </div> 
</body> 
</html> 

我该怎么办?

回答

0

如果我理解你的权利,该代码会是这个样子:

<html> 
 
<head> 
 
<style> 
 
    .passwordProtected { 
 
     display:none; 
 
    } 
 
</style> 
 
</head> 
 
<body> 
 
    <div id="loginArea"> 
 
     <input type="password"> 
 
     <button onclick='showDiv();'>Show div</button> 
 
    </div> 
 
    <div id="passwordprotected" class="passwordProtected"> 
 
     <h1>This is the protected div they enter</h1> 
 
    </div> 
 
    <script type="text/javascript"> 
 
    \t function showDiv(){ 
 
    \t \t \t var myDiv = document.querySelector('.passwordProtected'); 
 
    \t  \t \t myDiv.style.display = 'block'; 
 
    \t } 
 
    </script> 
 
</body> 
 
</html>

你可以找到更多关于使用JavaScript这里造型:http://www.w3schools.com/jsref/dom_obj_style.asp

+0

谢谢!对不起,迟到的回答!但这没有密码,人们将不得不输入!所以这是行不通的 –