使用jQuery Validation Plugin v1.13.1进行无验证 [英] No Validation using jQuery Validation Plugin v1.13.1

查看:79
本文介绍了使用jQuery Validation Plugin v1.13.1进行无验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我得到的错误:未捕获的TypeError:无法读取未定义的属性'element'

我在这里想不到的东西一定在我的鼻子底下.我无法在对话框中进行验证.我已经尝试了在寻找解决方案时发现的所有问题,但无法弄清楚自己做错了什么.我有一个jsfiddle https://jsfiddle.net/g6rnbtbj/21/代码示例.如果我取消注释jQuery下面的代码行,甚至不会显示该对话框.

I'm missing something here that must be right under my nose. I can't get the validation to work within the dialog. I have tried all the things I have found while searching for a solution but I can't figure out what I have done wrong. I have a jsfiddle https://jsfiddle.net/g6rnbtbj/21/ code example. If I un-comment the code line below the jQuery will not even display the dialog.

$('#business-partner-detail').validate();

请有人指出我做错了什么.我正在拔头发,我再也承受不了损失.

Someone please point out what I have done wrong. I'm pulling my hair out and I can't afford to lose any more.

非常感谢您提供任何见解.

Thanks a lot for any insights.

推荐答案

有人请指出我做错了."

"Someone please point out what I have done wrong."

  1. 您的JavaScript控制台错误是由$('#activity-event-dialog').valid()引起的.您不能将.valid()方法附加到<div>.您只能将.valid()方法附加到<input><textarea><select><form>元素.对于您的情况,您想测试<form>本身,因此需要使用$('#business-partner-detail').valid().您也必须先调用.validate()进行初始化,才能调用.valid().

  1. Your JavaScript console error(s) is/are being caused by $('#activity-event-dialog').valid(). You cannot attach the .valid() method to a <div>. You can only attach the .valid() method to an <input>, <textarea>, <select> or <form> element. In your case, you want to test the <form> itself so you need to use $('#business-partner-detail').valid(). You also cannot call .valid() without first calling .validate() to do the initialization.

您不能注释掉.validate()方法,因为初始化窗体上的插件是必需的.没有它,jQuery Validate将无法执行任何操作.

You cannot comment out the .validate() method as it's required for initializing the plugin on your form. Without it, jQuery Validate will do nothing.

您尚未声明任何验证规则,因此该插件仍然无法执行任何操作.作为测试,我在下面的演示中将required="required"属性放在了您的<textarea>元素内.否则,您可以在.validate()方法中使用 rules选项声明规则.

You have not declared any validation rules so the plugin will still do nothing. As a test, I've placed the required="required" attribute within your <textarea> element in the demo below. Otherwise, you can declare rules using the rules option within the .validate() method.

您的jsFiddle 包括两个jQuery实例...版本1.11.0 框架和扩展"部分以及外部资源"部分中的1.11.2版本.删除其中之一.

Your jsFiddle includes two instances of jQuery... version 1.11.0 in the "Frameworks & Extensions" section and version 1.11.2 in the "External Resources" section. Remove one of these.

正在运行的演示: https://jsfiddle.net/g6rnbtbj/25/

Working DEMO: https://jsfiddle.net/g6rnbtbj/25/

这篇关于使用jQuery Validation Plugin v1.13.1进行无验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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