2017-10-24 10 views
-2

私はこれを何時間も解決しようとしてきましたが、どうすればいいのかわかりません - 私はあきらめました。JavaScriptログインが正しく機能しないのはなぜですか?

誰かが下記のコードを見て、 が間違っていることを理解できますか?

プログラムのアイデアは、ユーザーがユーザー名とパスワードを入力できるようにすることで、正常に確認されたらURLにリダイレクトされます。

<html> 
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600' rel='stylesheet' type='text/css'> 
<link href="//netdna.bootstrapcdn.com/font-awesome/3.1.1/css/font-awesome.css" rel="stylesheet"> 
<style> 
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, 
pre, form, fieldset, input, textarea, p, blockquote, th, td { 
    padding:0; 
    margin:0;} 

fieldset, img {border:0} 

ol, ul, li {list-style:none} 

:focus {outline:none} 

body, 
input, 
textarea, 
select { 
    font-family: 'Open Sans', sans-serif; 
    font-size: 16px; 
    color: #4c4c4c; 
} 

p { 
    font-size: 12px; 
    width: 150px; 
    display: inline-block; 
    margin-left: 18px; 
} 
h1 { 
    font-size: 32px; 
    font-weight: 300; 
    color: #4c4c4c; 
    text-align: center; 
    padding-top: 10px; 
    margin-bottom: 10px; 
} 

html{ 
    background-color: #ffffff; 
} 

.testbox { 
    margin: 20px auto; 
    width: 343px; 
    height: 464px; 
    -webkit-border-radius: 8px/7px; 
    -moz-border-radius: 8px/7px; 
    border-radius: 8px/7px; 
    background-color: #ebebeb; 
    -webkit-box-shadow: 1px 2px 5px rgba(0,0,0,.31); 
    -moz-box-shadow: 1px 2px 5px rgba(0,0,0,.31); 
    box-shadow: 1px 2px 5px rgba(0,0,0,.31); 
    border: solid 1px #cbc9c9; 
} 

input[type=radio] { 
    visibility: hidden; 
} 

form{ 
    margin: 0 30px; 
} 

label.radio { 
    cursor: pointer; 
    text-indent: 35px; 
    overflow: visible; 
    display: inline-block; 
    position: relative; 
    margin-bottom: 15px; 
} 

label.radio:before { 
    background: #3a57af; 
    content:''; 
    position: absolute; 
    top:2px; 
    left: 0; 
    width: 20px; 
    height: 20px; 
    border-radius: 100%; 
} 

label.radio:after { 
    opacity: 0; 
    content: ''; 
    position: absolute; 
    width: 0.5em; 
    height: 0.25em; 
    background: transparent; 
    top: 7.5px; 
    left: 4.5px; 
    border: 3px solid #ffffff; 
    border-top: none; 
    border-right: none; 

    -webkit-transform: rotate(-45deg); 
    -moz-transform: rotate(-45deg); 
    -o-transform: rotate(-45deg); 
    -ms-transform: rotate(-45deg); 
    transform: rotate(-45deg); 
} 

input[type=radio]:checked + label:after { 
    opacity: 1; 
} 

hr{ 
    color: #a9a9a9; 
    opacity: 0.3; 
} 

input[type=text],input[type=password]{ 
    width: 200px; 
    height: 39px; 
    -webkit-border-radius: 0px 4px 4px 0px/5px 5px 4px 4px; 
    -moz-border-radius: 0px 4px 4px 0px/0px 0px 4px 4px; 
    border-radius: 0px 4px 4px 0px/5px 5px 4px 4px; 
    background-color: #fff; 
    -webkit-box-shadow: 1px 2px 5px rgba(0,0,0,.09); 
    -moz-box-shadow: 1px 2px 5px rgba(0,0,0,.09); 
    box-shadow: 1px 2px 5px rgba(0,0,0,.09); 
    border: solid 1px #cbc9c9; 
    margin-left: -5px; 
    margin-top: 13px; 
    padding-left: 10px; 
} 

input[type=password]{ 
    margin-bottom: 25px; 
} 

#icon { 
    display: inline-block; 
    width: 30px; 
    background-color: #3a57af; 
    padding: 8px 0px 8px 15px; 
    margin-left: 15px; 
    -webkit-border-radius: 4px 0px 0px 4px; 
    -moz-border-radius: 4px 0px 0px 4px; 
    border-radius: 4px 0px 0px 4px; 
    color: white; 
    -webkit-box-shadow: 1px 2px 5px rgba(0,0,0,.09); 
    -moz-box-shadow: 1px 2px 5px rgba(0,0,0,.09); 
    box-shadow: 1px 2px 5px rgba(0,0,0,.09); 
    border: solid 0px #cbc9c9; 
} 

.gender { 
    margin-left: 30px; 
    margin-bottom: 30px; 
} 

.accounttype{ 
    margin-left: 8px; 
    margin-top: 20px; 
} 

a.button { 
    font-size: 14px; 
    font-weight: 600; 
    color: white; 
    padding: 6px 25px 0px 20px; 
    margin: 10px 8px 20px 0px; 
    display: inline-block; 
    float: right; 
    text-decoration: none; 
    width: 50px; height: 27px; 
    -webkit-border-radius: 5px; 
    -moz-border-radius: 5px; 
    border-radius: 5px; 
    background-color: #3a57af; 
    -webkit-box-shadow: 0 3px rgba(58,87,175,.75); 
    -moz-box-shadow: 0 3px rgba(58,87,175,.75); 
    box-shadow: 0 3px rgba(58,87,175,.75); 
    transition: all 0.1s linear 0s; 
    top: 0px; 
    position: relative; 
} 

a.button:hover { 
    top: 3px; 
    background-color:#2e458b; 
    -webkit-box-shadow: none; 
    -moz-box-shadow: none; 
    box-shadow: none; 

} 

</style> 
<body> 
<div class="testbox"> 
    <h1>Login</h1> 

    <form action="/"> 
     <hr> 
    <div class="accounttype"> 
     <input type="radio" value="None" id="radioOne" name="account" checked/> 
     <label for="radioOne" class="radio" chec>Student</label> 
     <input type="radio" value="None" id="radioTwo" name="account" /> 
     <label for="radioTwo" class="radio">Teacher</label> 
    </div> 
    <hr> 
    <label id="icon" for="name"><i class="icon-envelope "></i></label> 
    <input type="text" name="userid" id="name" placeholder="Username/Email"/> 

    <label id="icon" for="name"><i class="icon-user"></i></label> 
    <input type="text" name="insid" id="ins" placeholder="Institution Code"/> 

    <label id="icon" for="name"><i class="icon-shield"></i></label> 
    <input type="password" name="pswrd" id="pass" placeholder="Password"/> 

    <div class="gender"> 
    <input type="radio" value="None" id="male" name="gender" checked/> 
    <label for="male" class="radio" chec>Primary</label> 
    <input type="radio" value="None" id="female" name="gender" /> 
    <label for="female" class="radio">Secondary</label> 
    </div> 
    <p>By clicking Login, you agree on our <a href="#">terms and condition</a>.</p> 
    <a class="button" onClick="check(this.form)">Login</a> 
    </form> 
    <script language="javascript"> 
function check(form) 
{ 
if(form.userid.value == "myuserid" && form.pswrd.value == "mypswrd") 
    { 
    window.open('www.google.com')/*opens the target page while Id & password matches*/ 
    } 
</script> 
</body> 
</html> 
+2

CSSを別のファイルに移動したり、コードブロックから完全に削除したりできますか?それは多くのスペースを占めます。 – Edric

+0

これは学校用ではありません。これは私が設定しているウェブサイト用です。私はこれがログインを設定する最も効果的な方法ではないことを知っていますが、それは簡単に管理できる方法です。 – championj

+0

あなたが探しているパスワードがコードの中にある場合は、コードをもっと隠す必要があります。誰でもF12を押すだけでパスワードを調べることができます。 – Shilly

答えて

0

いくつかの問題:私はそれがここで適切に が動作していないJavascriptがコードであると思います。

  • check機能のブレースを閉じる必要があります。
  • Teemuが述べたように、ハイパーリンクはフォームへの参照を持たないため、おそらく入力タイプのボタンなどの入力要素を使用する必要があります。ハイパーリンクを維持したい場合は、querySelectorなどの方法を使用して、ユーザーIDとパスワードの入力フィールドを取得します。
  • ハイパーリンクが機能しない可能性があります。このサイトのホスト方法によっては、リンクの前にhttp://を追加することができます。

これらの3つのものを変更すると、ページは自分のパソコンで動作します。 このログインを深刻なものに使用する予定の場合は、より良いシステムを見つけてください。 フロントエンドコードにユーザー名とパスワードを入力すると、誰でも任意のユーザーとしてログインできます。

関連する問題