首先这是我的代码
好的,我的问题是,当尝试使用注册表单时,它不会调用代码。
我已经检查了好几次,似乎找不到我在同一页面上使用登录脚本的问题,这似乎很好。
登录.js
$(function() {
// Expand
$("#open").click(function(){
$("div#panel").slideDown("slow");
});
// Collapse
$("#close").click(function(){
$("div#panel").slideUp("slow");
});
// Change Text
$("#toggle a").click(function () {
$("#toggle a").toggle();
});
// Login proccess Start
$('.error').hide();
$(".bt_login").click(function() {
// validate input
$('.error').hide();
var username = $("input#username").val();
if (username == "") {
$("label#username_error").show();
$("input#username").focus();
return false;
}
var password = $("input#password").val();
if (password == "") {
$("label#password_error").show();
$("input#password").focus();
return false;
}
var rememberMe = $("input#rememberMe").val();
// correct data sent
var dataString = 'username='+ username + '&password=' + password + '&submit=Login' + '&rememberMe=' + rememberMe;
alert (dataString);return false;
$.ajax({
type: "POST",
url: "../../inc/files/login.php",
data: dataString,
success: function() {
return false;
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$('#login_form').html("<div id='message'></div>");
$('#message').html("<h2>!</h2>")
.append("<p>Error Details; <br /> Status: ", textStatus, " <br /> Error thrown: ", errorThrown,"</p>")
.hide()
.fadeIn(1500, function() {
$('#message').append("<img id='cross' src='images/cross.png' />");
});
return false;;
}
});
});
// End login proccess
//Registration Process start
$("bt_register").click(function() {
// validate inpu
$('.error').hide();
var username2 = $("input#username2").val();
if (username2 == "") {
$("label#username2_error").show();
$("input#username2").focus();
return false;
}
// var re = new RegExp("/[^a-z0-9\-\_\.]+/i");
// if(re.test(username2) = true) {
// $("label#username2_error2").show();
// $("input#username2").focus();
// return false;
// }
var password2 = $("input#password2").val();
if (password2 == "") {
$("label#password2_error").show();
$("input#password2").focus();
return false;
}
var email = $("input#email").val();
if (password == "") {
$("label#email_error").show();
$("input#email").focus();
return false;
}
// correct data sent
var dataString = 'username='+ username2 + '&password=' + password2 + '&submit=Register' + '&email=' + email;
alert (dataString);return false;
$.ajax({
type: "POST",
url: "../../inc/files/login.php",
data: dataString,
success: function() {
return false;
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$('#reg_form').html("<div id='message'></div>");
$('#message').html("<h2>!</h2>")
.append("<p>Error Details; <br /> Status: ", textStatus, " <br /> Error thrown: ", errorThrown,"</p>")
.hide()
.fadeIn(1500, function() {
$('#message').append("<img id='cross' src='images/cross.png' />");
});
return false;
}
});
});
});
调用 Jquery 的 html 表单
<div id="reg_form">
<form class="clearfix" action="" >
<h1>Register Here!</h1>
<label class="grey" for="username">Username:</label>
<input class="text-input" type="text" name="username2" id="username2" value="" size="23" />
<label class="error" for="username2" id="usernamename2_error">This field is required.</label>
<label class="error" for="username2" id="usernamename2_error2">Your username contains invalid characters!</label>
<label class="grey" for="email">Email:</label>
<input class="text-input" type="text" name="email" id="email" size="23" />
<label class="error" for="email" id="email_error">This field is required.</label>
<label class="grey" for="password2">Password:</label>
<input class="text-input" type="password" name="password2" id="password2" size="23" />
<label class="error" for="password2" id="password2_error">This field is required.</label>
<input type="submit" name="submit" value="Register" class="bt_register" />
</form>
</div>