我需要问一个快速的问题,可能是一个愚蠢的问题,因为我是JQuery的新手,为什么这个脚本不起作用? 它看起来很好但是没有做任何事我需要在HTML中调用函数吗?
<td>UserName</td>
<input type="text" name="user_login" id="user_login">
<br>
<td>Password</td>
<input type="password" name="user_pass" id="user_pass">
<br>
<td><input type="checkbox" name="remember_me" id="remember_me"> </td><td>Remember Me For 2 Days</td>
</tr><br>
<tr id="button_box">
<td> </td>
<td><input type="button" name="submit" value="Sign In" class="button" onclick="check(e)"></td>
</tr>
<tr><td colspan="2" id="flash"></td></tr>
</div>
JS
$(document).ready(function () {
// Make a function that returns the data, then call it whenever you
// need the current values
function getData() {
return {
user_login: $('#user_login').val(),
pass_login: $('#user_pass').val()
}
}
function loading(e) {
$('#content').html('Loading Data');
}
function clearfields() {
$('#user_login').val(''); //Clear the user login id field
$('#pass_login').val(''); //Clear the user login password field
}
function check(e) {
e.preventDefault();
$.ajax({
url: 'ajax/check.php',
type: 'post',
error: function () {
//If your response from the server is a statuscode error. do this!!!
clearfields();
},
beforeSend: function () {
$('#loading').fadeIn(800);
//loading(e);
},
data: { user_login: $('#user_login').val(), pass_login: $('#pass_login').val() }, // get current values
success: function (data) {
//if your response is a plain text. (e.g incorrect username or password)
if (data.indexOf("incorrect username or password") > -1) {
clearfields();
}
$('#loading').fadeOut();
$('#content').hide();
$('#content').fadeIn(1000).html(data);
}
});
}
// Don't repeat so much; use the same function for both handlers
$('#field').keyup(function (e) {
if (e.keyCode == 13) {
var username = $('#user_login').val();
check(e);
}
});
$('#submit').click(function (e) {
if (e.keyCode != 13) {
check(e);
}
});
});