English 中文(简体)
• 如何向某类人提供附加《规则》的信息
原标题:How to add messages to a class with addClassRules

http://docs.jquery.com/Plugins/Validation”rel=“noreferer”j Query Validate,用大量重复的数据浏览对网页进行验证。 由于空间有限,每一行都有自己的鉴定摘要。

我用添加《物证规则》对页数适用审定规则,但缺省错误信息在摘要中过于笼统(例如,“需要现场,需要现场等)。

例:

jQuery.validator.addClassRules({
amount: {
    required: true,
    range: [0, 2000000]
},
comment: {
    maxlength: 51
},
owner: {
    notFirstOption: true
},
A: {
    required: function (element) {  
        return getParentElement($(element), "tr").find(".colB input.B").val().length > 0;
    },
    digits: true
}});

您能否对每一验证类别的规则适用习惯信息? 理想的情况是:

jQuery.validator.addClassMessages({
    amount: {
        required: "Amount is required",
        range: "Amount must be between 0 and 2,000,000"
    },
    comment: {
        maxlength: "Comment may be a maximum of 51 characters"
    },
    owner: {
        notFirstOption: "Please select an owner"
    },
    A: {
        required: "A is required if B is entered",
        digits: "A must be numeric"
    }});

事先感谢你们能够提供的任何帮助。

最佳回答
问题回答

可以用以下代码进行:

  $.validator.messages.accept =  File must be JPG, GIF or PNG ;

    $.validator.addClassRules("files", {            
      accept : "png|jpe?g|gif",  
      filesize : 2000000
    });

我提出了极具可耻的解决办法,但希望有一个更清洁、时间比较少的东西。

无论如何,通过j Query元数据分配电文,Im 能够按级定制。

class="amount {validate:
                {messages:
                  {required: Amount is required ,
                   range:  Amount must be between 0 and 2,000,000 ,
                   digits:  Amount must be numeric }
                }
              }"

......并按我电网各行各处。

我正在考虑扩大添加集束器法,以接受电文参数,但现在这项工作却如此。

既然大家显然有兴趣对此作出回应,那么我寻求答案的下一步就是这样。

我将一些方法添加到阴 p中,以便添加阶级信息,并修正了缺省信息手来删除这些信息。

在习俗之前添加 梅塔塞斯

customClassMessage: function (element, method) {
    //Get the elements class(es)
    var classes = $(element).attr("class").split(" ");

    //return any message associated with said class and method
    var m = $.validator.messages[classes[0]];

    return m && (m.constructor == String
        ? m
        : m[method]);
},

修正的缺省 发出电文,呼吁采用上述方法

defaultMessage: function (element, method) {
                return this.findDefined(
                this.customMessage(element.name, method),
                this.customMetaMessage(element, method),
                this.customClassMessage(element, method),
                // title is never undefined, so handle empty string as undefined
                !this.settings.ignoreTitle && element.title || undefined,
                $.validator.messages[method],
                "<strong>Warning: No message defined for " + element.name + "</strong>"
            );
            },

添加加薪方法

        addClassMessages: function (className, messages) {
        if (className.constructor == String) {
            $.validator.messages[className] = messages != undefined ? messages : $.validator.messages[className];
        }
        else {
            $.extend(this.messages, className);
        }
    },

我没有能够研究如何把这些额外方法放在原状之外。 至少,我不必说谎话。

jQuery.validator.addClassMessages({
    amount: {
        required: "Amount is required",
        range: "Amount must be between 0 and 2,000,000",
        digits: "Amount must be numeric"
    }
});

使用data-msg-required=>Error information here",内容为你希望作验证

<select name="account1" data-msg-required="Please select an account">
<option value="">--Select Account--</option>
<optgroup label="100-Assets">
    <option value="1">A</option>
    <option value="2">B</option>
    <option value="3">C</option>
    <option value="4">D</option>
</optgroup>

为此:

jQuery.validator.addClassRules({
    amount: {
        required: true,
        range: [0, 2000000],
        messages: {required: "Required field!", range: "Invalid range!"}
    },
    comment: {
        maxlength: 51,
        messages: {maxlength: "Max 51 characters!"}
    }
})

我认为,你们正在寻求什么是正确的?





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签