私はjsとjqueryで作業しています。私が取り組んでいるテスト ログイン ページがあり、ログイン ボタンのバインドに問題があるようです。Chrome では、js ファイルが読み込まれていることがわかりますが、ボタンをクリックするとページが更新されます。間違った情報を入力してもアラート セクションは表示されず、シェイクもされず、正しい情報を入力してもメイン ページにリダイレクトされません。これが私のコードです:
HTML:
<body>
<div id="content">
<section class="ui-widget ui-corner-all">
<header class="ui-widget-header ui-corner-top">
Test Login
</header>
<div class="ui-widget-content ui-corner-bottom">
<p class="ui-state-error">Uername / Password Incorrect.</p>
<form>
<div>
<label for="username">Username:</label>
<input id="username" type="text">
</div>
<div>
<label for="password">Password:</label>
<input id="password" type="password">
</div>
<div>
<input id="btnLogin" type="submit" value="Login">
</div>
</form>
</div>
</section>
</div>
<div class="ui-widget-overlay" style"z-index: 1002;"> </div>
</body>
JS:
$(".ui-state-error").hide();
$("#btnLogin").button()
.bind ("click", function() {
if($("#username").val() != "test" && $("#password").val() != "test") {
$(".ui-state-error").show();
$("#login section").effect("shake", 150);
}
else {
document.location = 'index.html';
}
return false;
});