jQuery Validate 是否与表单按钮(图像/超链接)以外的提交功能发生冲突?
我将举几个我遇到的表单问题的例子。我已经因为使用“强迫性 js”并试图作为一名程序员做得更好而受到批评,但是当“强迫性 js”起作用而非强迫性 JS 不起作用时,这让我感到非常沮丧。总体目标是为除实际表单 type=submit 按钮(在本例中为图像链接)之外的其他内容提供类似 Submit() 的行为。
示例 1
这里的理论是,单击 ID“pw_submit”时,表单输入将被禁用(有效),调用提交函数来触发验证。后者不会发生。继续前进。
示例 2 -
请参阅此 JS 小提琴: http://jsfiddle.net/YkuAk/
可以使用,但使用常规 html 按钮,不是我想要/需要的
正如我上面提到的,示例 2 在调用 validate 的意义上“有效”,但它没有实现我们使用超链接、图像等来初始化 Submit() 函数的目标。
示例 3 - “obtrusive JS”
第三个使用 Obtrusive Javascript 的示例 这个例子工作没有任何问题,但正如我上面提到的,由于使用内联 js 而受到批评。虽然在我看来它与示例一中的代码没有什么不同,但显然确实如此。
有什么想法吗?
I will give a few examples of the form issue I am running into. I have already been chastised for using 'obstrusive js' and trying to do a better job as a programmer but it makes it utterly frustrating when the 'obtrusive js' works and the unobtrusive does not. The overall goal is give submit() like behavior to something other than an actual form type=submit button, in this case an image link.
EXAMPLE 1
Theory here would be that on the click of ID "pw_submit", the form input is disabled (works), the submit function is called which triggers validate. The latter does not happen. Moving on.
EXAMPLE 2 -
See this JS fiddle: http://jsfiddle.net/YkuAk/
Works but with regular html button, not what I want/need
As I mention above, example 2 "works" in the sense validate is called but it does NOT achieve our goal of using a hyperlink, image, etc to initialize the submit() function.
EXAMPLE 3 - "obtrusive JS"
Third example with Obtrusive Javascript
This example works without any issue but as I mention above, have been criticized for using inline js. While in my mind it is NO different than the code in example one, clearly it is.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
验证插件将其自己的侦听器绑定到表单提交事件。在第一个小提琴中,将
$("#someform").validate();
放在点击事件回调之外。现在的情况是,插件正在向表单添加另一个提交侦听器。编辑:
误读小提琴。验证插件不会验证禁用的输入。
src: http://forum.jquery.com/topic/jquery -jquery-validate-validating-disabled-inputs
the validation plugin binds its own listener to form submit event. In the first fiddle, take the
$("#someform").validate();
outside of the click event callback. The way it is now, the plugin is adding another submit listener to the form.EDIT:
misread the fiddle. The validation plugin doesn't validate disabled inputs.
src: http://forum.jquery.com/topic/jquery-jquery-validate-validating-disabled-inputs
我不确定 - 可能已经找到答案,但在示例 1 中,当我删除事件以禁用输入字段时 - 函数似乎运行正常。进一步测试但不确定为什么会出现这种情况。
I am not sure - may have found the answer but in Example 1, when I remove the event to disable input fields - it appears the function runs properly. Testing further but not sure why this is the case regardless.