jQuery 验证文本区域:已填充
我有以下表单字段...
<textarea name="anchors[]" id="anchors1" cols="45" rows="5" class="linkbox"></textarea>
<textarea name="anchors[]" id="anchors2" cols="45" rows="5" class="linkbox"></textarea>
<textarea name="urls[]" id="urls1" cols="45" rows="5" class="linkbox"></textarea>
<textarea name="urls[]" id="urls2" cols="45" rows="5" class="linkbox"></textarea>
我正在尝试验证这些字段,以便如果填写了anchors2,则也必须填写urls2,但是我一生都无法让以下内容正常工作! ..
var validator = $("#projectform").validate({
rules: {
project_label: "required",
keywords: "required",
urls2: { required: "#anchors2:filled" }
},
messages: {
project_label: "Enter a project label",
}
,errorElement: "div"
,submitHandler: function(form) {
$('input[type=submit]').attr('value', 'Please wait');
$('input[type=submit]').attr('disabled', 'disabled');
this.form.onsubmit(); return false;
}
});
当我单击“提交”时,project_label 和 keywords 字段会按预期进行验证(或不验证),但是我没有看到有关 anchors[] 和 urls[] 字段的任何内容。我在 textarea.error 上设置了 css,也给出了视觉指示,但在尝试验证时我也没有看到这一点。
应该指出的是,以下内容也不起作用,这可能会带来一些启发?
urls1: "required",
i have the following form fields...
<textarea name="anchors[]" id="anchors1" cols="45" rows="5" class="linkbox"></textarea>
<textarea name="anchors[]" id="anchors2" cols="45" rows="5" class="linkbox"></textarea>
<textarea name="urls[]" id="urls1" cols="45" rows="5" class="linkbox"></textarea>
<textarea name="urls[]" id="urls2" cols="45" rows="5" class="linkbox"></textarea>
which i'm trying to validate so that if say anchors2 is filled in, then urls2 must also be filled in, however i can't for the life of me get the following to work!...
var validator = $("#projectform").validate({
rules: {
project_label: "required",
keywords: "required",
urls2: { required: "#anchors2:filled" }
},
messages: {
project_label: "Enter a project label",
}
,errorElement: "div"
,submitHandler: function(form) {
$('input[type=submit]').attr('value', 'Please wait');
$('input[type=submit]').attr('disabled', 'disabled');
this.form.onsubmit(); return false;
}
});
When i click submit the project_label and keywords fields validate(or not) as would be expected, however i see nothing with regards to the anchors[] and urls[] fields. I have css set on the textarea.error to give a visual indiciation too but i don't see that either when attempting to validate.
It should be noted that the following doesn't work either, which may shed some light?
urls1: "required",
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
验证插件要求您使用元素 name,而不是 id。为了做到这一点,我必须更改名称以删除 []。因此,重命名您的文本区域,然后重试 - 就像这样:
HTML:
Javascript Snippet:
The validation plugin requires that you use the element name, not the id. In order to do this, I had to change the name to remove the []. So rename your textarea, and try again - like so:
HTML:
Javascript Snippet: