开发者

Returning a element's id using its name with jQuery

I'm making a custom jQuery validation method:

        jQuery.validator.addMethod("workaround", function(input, element) {
      开发者_StackOverflow中文版      if (!($(/*asdf*/).hasClass("intra-field-label"))) 
            {
                return true;
            } 
        }, "This is required");

input is the 'name' of the element. I am trying to get the 'id' of the element, or if I can simply check for the presence of a class using only a 'name', then I want to do that.


jQuery.validator.addMethod("workaround", function(input, element) {
        if (!($("input[name=" + input + "]").hasClass("intra-field-label"))) 
        {
            return true;
        } 
    }, "This is required");

Considering that your element will always be an <input />.

Otherwise change to $("[name=" + input + "]")


Actually, I don't think the first argument, input, is the name of the element. It should be the value the input currently holds, according to the example given in the documentation.

The second argument is the element that is being validated. Therefore you can simply check:

if ($(element).hasClass('intra-field-label'))


Box9 is correct, the first parameter is the value, the second is the element containing the value. As you know you can also get the value by element.value

 $.validator.addMethod("ValidateAdUser", function (value, element)
        {
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜