jQuery Validation插件:如何检查元素是否有效? [英] jQuery Validation plugin: how to check if an element is valid?

查看:100
本文介绍了jQuery Validation插件:如何检查元素是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一点上下文:

我正在使用 jQuery Validation插件来验证注册表单。我现在想在系统中实现一个 ajax调用以检查用户名是否可用,并且只有当userName值是根据规则中设置的有效值时才想进行此ajax调用。 $(form).validate();

I'm using the jQuery Validation plugin to validate a sign-up form. I now want to implement an ajax call to check whether the user name is available in the system, and I want to make this ajax call only if the userName value is a valid one as per the rules set in $(form).validate();

我想要的东西:

$("#userName").keyup(function () {
    if ($("#userName").isValid()) {
        //make ajax called
    }
});

我搜索了文档但我找不到解决问题的方法。

I searched the documentation but i couldn't identify the solution to my problem.

推荐答案

$("#userName").keyup(function () {
    if ($("#userName").valid() == true ) {
        //make ajax called
    }
});

http://docs.jquery.com/Plugins/Validation/valid

注意:到那些没有点击链接的人。你必须先调用 $(#myform)。validate();

Note: To those who do not click the link. You have to call $("#myform").validate(); first.

这篇关于jQuery Validation插件:如何检查元素是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆