Jquery,qunit 选择一个类名的子字符串
我正在编写 Qunit 测试来测试我们网站上表单的验证引擎。表单的结构是标准的,具有以下元素:
我想在 Qunit 中编写一个测试来验证何时满足条件(必需或在长度 1-255 内),会弹出一个小警告 jpeg在页面上。
我想将其编写为可扩展的,因此我想选择页面上在类中具有 validate 关键字的所有元素,但也能够区分具有不同类型验证的元素,例如页面上的所有元素是必需的,或者是必需的,并且需要检查长度等。我基本上不知道如何选择和解析类名。感谢您的帮助。
I am writing Qunit tests to test the validation engine of forms on our site. The structure of the form is standard with elements like the following:
<input id="name" class="validate[required,length[1,255]] amp_validation_error_field" type="text" value="" title="Name" name="name">
And I want to write a test in Qunit to verify that when or not the conditions are met (required or within the length 1-255) that a little warning jpeg pops up on the page.
I want to write this to be extensible so I want to select all elements on the page that have the validate keyword in the class but also be able to distinguish between the elements with different types of validation, for example all the elements on the page that are required, or required and with checking the length, etc etc. I don't know how to select and parse the classname basically. Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个好的开始:http://jsfiddle.net/morrison/jgay7/
我不想自己承担所有工作,但我编写的扩展将获取第二个验证参数的值,在本例中它将从长度中选择 [1,255]。它返回一个数组数组,其中内部数组保存前面提到的值。这应该是您解析所需内容的良好基础。
如果您需要更多指导,请发表评论。
A good start: http://jsfiddle.net/morrison/jgay7/
I didn't want to take all the work on myself, but that extension I wrote will get the values of the second validate parameter, in this case it would select [1,255] from length. It returns an array of arrays, where the inner array holds the values previously mentioned. This should be a good base for you to parse out what you want.
Comment if you need more direction.