2016-05-15 3 views
1

私はワードプレスのクライアント用のウェブサイトで働いていました。ログインボタンをクリックするとHTML、CSS、Javascriptが書かれ、ドロップダウンメニューが表示されます。 onclick関数は機能していましたが、現在はありません。なぜそれが動作していないのか分かりません。ウェブサイトはhttp://outsourceyourjobsearch.com/builder/です。私は彼が彼のウェブサイトのために選んだテーマのために、1つのファイルにすべてのコードを書く必要があります。私のクリックをクリックするとウェブページ上で動作しません

<!DOCTYPE html> 
<html> 
<head> 
    <style> 
     .dropbtn { 
      background-color: #4CAF50; 
      color: white; 
      padding: 16px; 
      font-size: 16px; 
      border: none; 
      cursor: pointer; 
     } 

     .dropbtn:hover, .dropbtn:focus { 
      background-color: #3e8e41; 
     } 

     .dropdown { 
      position: relative; 
      float: right; 
      margin-right: 200px; 
     } 

     .dropdown-content { 
      display: none; 
      position: absolute; 
      background-color: #f9f9f9; 
      min-width: 160px; 
      overflow: auto; 
      box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);' 
     } 

     .dropdown-content a { 
      color: black; 
      padding: 12px 16px; 
      text-decoration: none; 
      display: block; 
     } 

     .dropdown a:hover { 
      background-color: #f1f1f1 
     } 

     .show { 
      display:block; 
     } 

     .button:hover span:after { 
      opacity: 1; right: 0; 
     } 

     .button span { 
      cursor: pointer; 
      display: inline-block; 
      position: relative; 
      transition: 0.5s; 
     } 

     .button { 
      width: 131px; 
      background-color: white; 
      color: black; 
      border: 2px solid #008CBA; 
      font-size: large; 
      margin-top: 8px; 
      margin-right: 75px; 
     } 

     .login-form{ 
      width: 300px; 
      padding-top: 5px; 
      padding-right: 5px; 
      padding-bottom: 5px; 
      padding-left: 5px; 
     } 

     input{ 
      font-size: large; 
      margin-top: 8px; 
     } 

     .register { 
      margin-left: 25px; 
      text-decoration: none; 
      font-size: small; 
      width: 80px; 
     } 

     .password{ 
      margin-left: 126px; 
      margin-top: -69px; 
      text-decoration: none; 
      font-size: small; 
     } 

     a:link { 
      text-decoration: none; 
     } 

     a:visited { 
      text-decoration: none; 
     } 

     a:active { 
      text-decoration: underline; 
     } 

     center{ 
      display: inline; 
      padding-left: 10px; 
      padding-right: 10px; 
     } 

    </style> 
    </head> 

    <body> 
     <div class="dropdown"> 
      <button onclick="myFunction()" class="dropbtn" > 
      Log In 
     </button> 
     <div id="myDropdown" class="dropdown-content"> 
      <form class="login-form"> 
       <input type="text" placeholder="username"/> 
       <input type="password" placeholder="password"/> 
       <button class ="button">login</button> 
       <div class = "center"> 
        <p><a  href="http://outsourceyourjobsearch.com/membership-account/membership-levels/" class="register">Register</a></p> <p><a href="http://outsourceyourjobsearch.com/wp-login.php?action=lostpassword" class="password">Forgot Password?</a></p> 
       </div>  
      </form> 
     </div> 
    </div> 

    <script> 
    /* When the user clicks on the button, toggle between hiding and showing the dropdown content */ 
    function myFunction() { 
     document.getElementById("myDropdown").classList.toggle("show"); 
    } 

    /* Close the dropdown if the user clicks outside of it */ 
    window.onclick = function(event) { 
     if (!event.target.matches('.dropbtn')) { 

      var dropdowns = document.getElementsByClassName("dropdown-content"); 
      var i; 
      for (i = 0; i < dropdowns.length; i++) { 
       var openDropdown = dropdowns[i]; 
       if (openDropdown.classList.contains('show')) { 
        openDropdown.classList.remove('show'); 
       } 
      } 
     } 
    } 
    </script> 

</body> 
</html> 
+0

* "時の機能は作動していましたが、今はありません" *あなたは何を意味するのか、または* – SimianAngel

+0

私はそれを変更しました。それはタイプミスでした。私はonclockを意味した – pgray10

+0

Onclock? 'onclock'とは何ですか? 'onclick'を意味しますか? –

答えて

1

ウェブサイトで使用している構造が正しくありません。私はそれをチェックして、あなたがそのHTMLであることを使用されるブロックで:

<div class="et_pb_fullwidth_code et_pb_module et_pb_fullwidth_code_0"> 
      <!DOCTYPE html> <html> <head> <style> .dropbtn { background-color: #4CAF50; color: white; padding: 16px; font-size: 16px; border: none; cursor: pointer; } .dropbtn:hover, .dropbtn:focus { background-color: #3e8e41; } .dropdown { position: relative; float: right; margin-right: 200px; } .dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; overflow: auto; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);' } .dropdown-content a { color: black; padding: 12px 16px; text-decoration: none; display: block; } .dropdown a:hover { background-color: #f1f1f1 } .show { display:block; } .button:hover span:after { opacity: 1; right: 0; } .button span { cursor: pointer; display: inline-block; position: relative; transition: 0.5s; } .button { width: 131px; background-color: white; color: black; border: 2px solid #008CBA; font-size: large; margin-top: 8px; margin-right: 75px; } .login-form{ width: 300px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; } input{ font-size: large; margin-top: 8px; } .register { margin-left: 25px; text-decoration: none; font-size: small; width: 80px; } .password{ margin-left: 126px; margin-top: -69px; text-decoration: none; font-size: small; } a:link { text-decoration: none; } a:visited { text-decoration: none; } a:active { text-decoration: underline; } center{ display: inline; padding-left: 10px; padding-right: 10px; } </style> </head> <body> <div class="dropdown"> <button onclick="myFunction()" class="dropbtn" > Log In </button> <div id="myDropdown" class="dropdown-content"> <form class="login-form"> <input type="text" placeholder="username"/> <input type="password" placeholder="password"/> <button class ="button">login</button> <div class = "center"> <p><a href="http://outsourceyourjobsearch.com/membership-account/membership-levels/" class="register">Register</a></p> <p><a href="http://outsourceyourjobsearch.com/wp-login.php?action=lostpassword" class="password">Forgot Password?</a></p> </div> </form> </div> </div> <script> /* When the user clicks on the button, toggle between hiding and showing the dropdown content */ function myFunction() { document.getElementById("myDropdown").classList.toggle("show"); } // Close the dropdown if the user clicks outside of it window.onclick = function(event) { if (!event.target.matches('.dropbtn')) { var dropdowns = document.getElementsByClassName("dropdown-content"); var i; for (i = 0; i < dropdowns.length; i++) { var openDropdown = dropdowns[i]; if (openDropdown.classList.contains('show')) { openDropdown.classList.remove('show'); } } } } </script> </body> </html> 
     </div> 

あなたは<div>タグ内<!DOCTYPE html> <html> <head>を持っており、それを持つべきではありません。

+0

あなたのコメントはもっと混乱してしまいました。コードをコピーしてその直前に行を追加したようです。 – pgray10

+0

@ pgray10 - ページを表示しているときにブラウザの「ソースの表示」を行います。マークアップが完全に崩れていることがわかります*。あなたは迷子/余分な '<!DOCTYPE html>'を持っています。これは確かにブラウザを投げ捨ててしまい、スクリプトがレンダリングされず、スクリプトが意図した通りに動作しなくなります。 –

0

私はあなたのコードを試しました。それは私のためにうまくいきます。

+0

これは解決策を提供するものではなく、コメントでなければなりません。 –

関連する問題