$(document).read()使jQuery验证需要两次点击

时间:2016-01-07 23:53:53

标签: jquery validation

我之前在stackoverflow上问过这个问题,但它仍然让我感到烦恼。我发现问题是jQuery验证代码在文档就绪函数内部。因为它在另一个功能中,所以它只在第二次点击后点击。所以,我有一个绝妙的想法,即我将它移出文档准备就绪,但现在它甚至没有在单击按钮时进行验证。我的问题是,如何调用一个函数而不必将其放在ready函数中?我已经看到人们发布类似的事情了,这很简单"。然而,无论我在哪里看,这个问题似乎都没有答案。我已经看到其他人使用异步假,但似乎确实有效,但其功能已被弃用。我的想法是,如果有一些方法可以在选择器上调用文档。

 $(document).ready(function() {
function func1(field,message) {
$(field).hover(function() {
$('#submenu').stop().fadeIn();
$('#submenu').html(message);
}, function() {
$('#submenu').stop().fadeOut();
});
}
func1('#first_name','This is the first name field. Please type slowly and carefully.');
func1('#last_name','This is the last name field.');
func1('#username','Username may be letters and numbers.');
func1('#password','A password phrase is stronger than a single password. Try interspersing words with special characters to create a strong password phrase.');
func1('#email','Please insert a valid e-mail address.');
});
/*$('#signup').validate();*/
/* Testing remote email validation */
/* Change remote: to "php_validation_scripts/check_(name)_field.php" */
$('#signup').unbind('hover').validate({ rules: {
email: {
    required: true,
    email: true,
    rangelength:[1,50],
    remote: "php_validation_scripts/check_email_field.php"
    },
password: {
    required: true,
    rangelength:[15,100],
    remote: "php_validation_scripts/check_password_field.php"
    },
username: {
    required: true,
    rangelength:[6,18],
    remote: "php_validation_scripts/check_username_field.php"
},
last_name: {
    required: true,
    rangelength:[1,50],
    remote: "php_validation_scripts/check_last_name_field.php"
},
first_name: {
    required: true,
    rangelength:[1,50],
    remote: "php_validation_scripts/check_first_name_field.php"
}
}})

0 个答案:

没有答案