2017-04-30 6 views
0

私は非常にjQueryを使い慣れていて、何か問題があります。私のプロジェクトには、フォームを使用したログイン/登録ページがあり、localStorageの使用に制限されています。プロジェクトを実行すると、サインインとサインアップのための送信ボタンが混乱しているように見えますが、IDタグはそれぞれ異なります。私は非常に混乱している、私は問題がおそらく非常にばかだと知っているが、私は数時間を探していて、それを修正することはできません。どんな助けもありがとう!クエリが迷惑なサブミットボタン

htmlコード:

<!DOCTYPE html> 
<html> 
<head> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"> 
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script> 
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> 
<script type="text/javascript" src="welcome.js"></script> 
</head> 
<body> 

<div data-role="page"> 
    <div data-role="header"> 
<h1>My Calendar</h1> 
    </div> 

    <div data-role="main" class="ui-content"> 
    <a href="#myPopup" data-rel="popup" class="ui-btn ui-btn-inline ui-btn-b ui-corner-all">Sign-in</a> 

<div data-role="popup" id="myPopup" class="ui-content" style="min-width:250px;"> 

    <form method="post" action=" "> 
    <div class="ui-field-contain"> 
    <label for="fullname">Full name:</label> 
    <input type="text" name="fullname" id="fullname">  

    <label for="email">E-mail:</label> 
    <input type="email" name="email" id="email" placeholder="Your email.."> 
    </div> 
    <input id="submit" type="submit" data-inline="true" value="Submit"> 
</form> 
</div> 
    </div> 


    <div data-role="main" class="ui-content"> 
<a href="#myPopup1" data-rel="popup" class="ui-btn ui-btn-inline ui-btn-b ui-corner-all">Sign-up</a> 

<div data-role="popup" id="myPopup1" class="ui-content" style="min-width:250px;"> 

    <form id="localStorageTest" method="post" action=" "> 
    <div class="ui-field-contain"> 
    <label for="fullname">Full name:</label> 
    <input type="text" name="fullname" id="fullname" class = "stored">  

    <label for="email">E-mail:</label> 
    <input type="email" name="email" id="email" placeholder="Your email.." class = "stored"> 
    </div> 
    <input id= "submitcheck" type="submit" data-inline="true" value="Submit"> 
</form> 
</div> 
    </div> 

</body> 
</html> 

のjQuery:

$(document).ready(function() { 

    if (localStorage["name"]&&localStorage["email"]) { 
     window.location.href = "calendar.html";} 
    else {$("<div>Incorrect Entry</div>").dialog();} 



$('#localStorageTest').submitcheck(function() { 
$('.stored').keyup(function() { 
localStorage[$(this).attr('name')] = $(this).val();} 
}); }); 
</script> 
+0

* "値段のわからない技術的な問題"はありません。また、 'submitcheck()'がjQueryコアメソッドではないので、何も分かりません – charlietfl

答えて

0

私はあなたのコードを見て、集めることができるものから、(私はあなたのコードhttps://jsfiddle.net/webbm/edfwoxxh/で、ここでフィドルを作った)、あなたがしようとしていますidのフォームの入力のチェックを行うlocalStorageTest

これを使用するようにコードを変更すると、サインアップ時に提出​​するときに正しい機能が適用されます:それは本当に意味がないので、

$('#localStorageTest').submit(function() { 
    /* Your code here */ 
}); 

あなたは、そこに$('.stored').keyup以外の何かをする必要があります。あなたの入力の値をチェックしたい場合は、次のようなことができます:

$('#localStorageTest').submit(function() { 
    var fullname = $('#fullname').val(); 
    var email = $('#email').val(); 
    if(fullname) { 
    //fullname has a value 
    } 
}); 
関連する問題