Jquery验证水印

发布于 2024-09-04 16:36:08 字数 412 浏览 11 评论 0原文

我正在使用 jQuery 验证插件和 水印插件。我面临的问题是,当我将水印应用于也应用了验证的任何输入字段时,验证失败

例如:

<input type=text name=myinput class="required">

并且我在文档就绪功能中为此字段应用了水印:

$("#myinput ").Watermark("myinput ");

这是验证失败的示例案例因为 value=myinput 是为带水印的输入字段设置的。

I am using jQuery validation plugin and Watermark plugin. The problem I am facing is when i applied a watermark to any input field for which validation is also applied then validations are failing

For Example:

<input type=text name=myinput class="required">

and I applied a watermark for this field in document ready function:

$("#myinput ").Watermark("myinput ");

This is the sample case where validation is failing as value=myinput is set for input field which is watermarked.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半世晨晓 2024-09-11 16:36:08

最后,我通过注册验证规则的方法并将其与该输入标记的类一起使用,得到了解决方案

$.validator.addMethod("watermark", Watermark, $.validator.messages["required"]);

function Watermark(value, element) {
            if (element.className.match("required") != null) {
                var id = "WM_" + element.name;
                return value != document.getElementById(id).value;
            }
            else
                return true;
        }

,对于输入标记使用此

<input type='text' class='required watermark'>

Finally i got the solution for this by registering a method for validation rules and using that along with the class for that input tag like

$.validator.addMethod("watermark", Watermark, $.validator.messages["required"]);

function Watermark(value, element) {
            if (element.className.match("required") != null) {
                var id = "WM_" + element.name;
                return value != document.getElementById(id).value;
            }
            else
                return true;
        }

And for input tag use this

<input type='text' class='required watermark'>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文