禁用 为特定提交按钮启用不显眼的验证
我有两个提交按钮“返回”、“继续”。当我单击“返回”时,我应该怎么做才能禁用客户端验证。我试图将 取消类 添加到按钮属性但它接缝没有帮助。
UPD。实际上,这是取消类。但如果你动态添加它(通过javascript),它似乎不起作用。
I have two submit buttons Back, Continue. What should I to do to disable client validation when I click on Back. I was trying to add cancel class to button attribute but It seams does not help.
UPD. Actually this is working cancel class. But It seams not working if you add it dynamically(by javascript).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我将一个事件处理程序附加到某些按钮,该事件处理程序更改了该特定表单上验证器对象的设置。
这在 MVC3 中对我来说就像一种魅力。
我不知道这是否对您特别有帮助,但由于我使用 ajax 表单,因此每次替换 ajax 表单的内容时,我都必须通过使用事件 ajax success 将事件附加到这些按钮。重新解析表单并将事件附加到取消按钮的完整代码是:
I attached an event handler to certain buttons, that altered the settings of the validator object on that particular form.
This has worked like a charm for me in MVC3.
I don't know if this helps you in particular, but since I use ajax form, I had to attach the event to these buttons each time the contents of the ajax form was replaced, by using the event ajax success. The full code that reparses the form and attaches the event to the cancel buttons is:
使用 JavaScript 劫持按钮单击以提交表单。
这是 jQuery 的一个很好的例子:
Hijack the button click for form submission using JavaScript.
Here is good example with jQuery:
这实际上是对 tugberk 答案的评论,但评论并不能很好地显示代码示例。
某些浏览器版本不喜欢“preventDefault()”函数。在被这个问题困扰了几次之后,我添加了一个简单的实用函数:
您可以像这样调用它来代替“preventDefault”:
This is really a comment to the answer by tugberk, but comments don't show code examples very well.
Some browser versions do not like the "preventDefault()" function. After being bitten by this a few times, I added a simple utility function:
You call it in place of "preventDefault" like this:
您可以使用“取消”CSS 类。
例如:
JQuery.Validate 处理以下代码中的其余部分:
You can use "cancel" css class.
Ex:
<input type="submit" value="Cancel" name="Cancel" class="cancel" />
JQuery.Validate handle the rest in the following code: