2015-11-12 28 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

謝謝!對不起,遲到的回答!但這沒有密碼,人們將不得不輸入!所以這是行不通的 –