DIV中显示为none的字段时的jquery验证

DIV中显示为none的字段时的jquery验证,jquery,jquery-validate,Jquery,Jquery Validate,我在显示字段上遇到问题:无。。。 我需要的是,在点击提交表单按钮后,即使要验证的字段位于div中,并且带有display:none设置,也会显示错误消息。 我找到了解决方案并尝试添加到jQuery代码设置中 ignore: [] 但这并没有改变任何事情。查看名为“moreurlinput”的类的div,他得到了内联样式display:none,但是如果您将其更改为display:inline(块、表等),则会出现验证错误 html })) 这里:验证工作完全按照预期进行。整个问题是错误元素也在

我在显示字段上遇到问题:无。。。 我需要的是,在点击提交表单按钮后,即使要验证的字段位于div中,并且带有display:none设置,也会显示错误消息。 我找到了解决方案并尝试添加到jQuery代码设置中

ignore: []
但这并没有改变任何事情。查看名为“moreurlinput”的类的div,他得到了内联样式display:none,但是如果您将其更改为display:inline(块、表等),则会出现验证错误

html

}))


这里

验证工作完全按照预期进行。整个问题是错误元素也在隐藏的
div
中,因此无法看到消息

解决方案是使用
errorPlacement
选项将消息放置在隐藏的
div
之外

errorPlacement: function(error, element) {
    error.insertAfter($(element).parent());
},
您还需要
ignore:[]
选项,以便不忽略任何内容,并验证隐藏的元素

工作演示:


另一种解决方案是将
display:none
移动到
input
元素,允许
div
保持可见

备选方案:


编辑

按钮
元素的HTML无效。您不应该使用“self-closing”标记,因为
元素本身是一个具有结束标记的容器

<button type="submit" />Add</button>
添加
应该是

<button type="submit">Add</button>
添加

验证工作完全按照预期进行。整个问题是错误元素也在隐藏的
div
中,因此无法看到消息

解决方案是使用
errorPlacement
选项将消息放置在隐藏的
div
之外

errorPlacement: function(error, element) {
    error.insertAfter($(element).parent());
},
您还需要
ignore:[]
选项,以便不忽略任何内容,并验证隐藏的元素

工作演示:


另一种解决方案是将
display:none
移动到
input
元素,允许
div
保持可见

备选方案:


编辑

按钮
元素的HTML无效。您不应该使用“self-closing”标记,因为
元素本身是一个具有结束标记的容器

<button type="submit" />Add</button>
添加
应该是

<button type="submit">Add</button>
添加