忽略jQuery验证插件中的默认文本 [英] Ignore default text in jquery validation plugin

查看:69
本文介绍了忽略jQuery验证插件中的默认文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery验证插件(bassistance.de/jquery-plugins/jquery-plugin-validation/id)进行一些客户端表单验证.该插件运行良好,但我无法弄清楚如何强制其忽略文本区域中的某些默认文本.

I am using the jquery validation plugin (bassistance.de/jquery-plugins/jquery-plugin-validation/id) for a bit of client-side form validation. The plugin is working great but I cannot figure out how to force it to ignore some default text within a textarea.

<form action="#" id="landingForm">
<p>
<textarea id="askTexarea" class="required textarea" name="askTextarea" cols="7" rows="3">THIS IS THE DEFAULT TEXT</textarea>
</p>
<p>
<label for="askExpert">Pick an Expert:</label>
<select id="askExpert" class="required select" name="askExpert">
    <option></option>
    <option>CHOICE 1</option>
    <option>CHOICE 2</option>
    <option>CHOICE 3</option>
</select>
</p>
<p class="email">
<label for="askEmail">Enter your email address:</label>
<input id="askEmail" class="required email" name="email" />
</p>
<p class="submit">
<input class="submit" type="submit" value="Ask a Question" />
</p>
</form>

您会注意到在第一个文本区域中有默认文本.有没有人知道如何使验证插件忽略此文本,并且如果用户使用此默认文本提交表单或textarea为空,则认为该文本无效?

You will notice in the first textarea there is default text. Does anyone know how to make the validation plugin ignore this text and consider it invalid if a user submits the form with this default text or if the textarea is empty?

预先感谢您的帮助!

推荐答案

您可以添加用于检查默认文本的自定义方法:

$.validator.addMethod("defaulText", function(value, element) {
  return this.optional(element) || element[0].defaultText != value;
}, "Please replace the default text");

尚未测试此实现-如果element [0] .defaultText没有提供正确的值,请用内联字符串替换.

Didn't yet test this implementation - if element[0].defaultText doesn't give the right value, replace that with an inline string.

这篇关于忽略jQuery验证插件中的默认文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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