开发者

How to make a 'cancel' button not trigger the forms validation?

How to make a 'cancel' button not trigger the forms validation?

I开发者_如何学编程'm using asp.net MVC with the jquery validation plugin.


Simply give it a cancel class:

<input type="submit" class="cancel" value="Submit without validation" />


You can define the validation group of the elements you're validating, as well as the buttons. http://www.dotnet-guide.com/validationgroups.html


Validation? Do you mean submission? If you want to cancel a form's submission, you have to return false on the form's submit event. See here:

http://jsfiddle.net/Bzz4J/


If you are using an html5 'button' tag, add the type="button" attribute. This indicates that the behavior is not to 'submit' the form which is the default behavior and what is causing the validation to fire.

<button id="cancel" type="button" onclick="window.location.href='./'">Cancel</button>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜