开发者

Conditionally wrap error message in jQuery Validation

开发者 https://www.devze.com 2023-02-08 09:33 出处:网络
I need to wrap an error message only if a certain condition is true. This means I can\'t use the wrapper property since it would always wrap the error message. So I\'m using errorPlacement() with the

I need to wrap an error message only if a certain condition is true. This means I can't use the wrapper property since it would always wrap the error message. So I'm using errorPlacement() with the following code.

    errorPlacement : function(error, element) {开发者_如何转开发
        if (condition == true) {
            error.wrap("<li></li>").appendTo(element);
        }
        else {
            ...
        }
    }

Somehow this code doesn't have the message wrapped. First, am I right to replace errorPlacement() to get what I want done? Second, what am I doing wrong to wrap the HTML text?


Try $('<li></li>').append(error).appendTo(element);

0

精彩评论

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