如何不验证HTML5文本框必需的属性 [英] How not to validate HTML5 text box with required attribute

查看:131
本文介绍了如何不验证HTML5文本框必需的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML文本框(对于数量)和两个HTML按钮(添加,取消)我的表单中。

I have one HTML text box (for quantity) and two HTML buttons (Add, Cancel) inside my form.

<form>
    <input type="number" min="1" max="100" required />
    <button type="button">Add</button>
    <button type="button">Cancel</button>
</form>

我不希望我的第二个按钮(取消),以验证表单点击时。

I do not want my second button (cancel) to validate the form when clicked.

这可能吗?在ASP.NET中,我可以使用的CausesValidation =false表示不会触发验证。

Is this possible? In ASP.NET, I can use CausesValidation="false" to not trigger the validation.

推荐答案

试试这个;

<button type="button" formnovalidate>Cancel</button>

我改变了你的code:
你需要的是你的形式不应该取消的点击进行验证,所以这就是为什么我添加了formnovalidate到按钮取消。

I changed your code: What you want is that your form should not be validated on click of cancel, so that's why i added the formnovalidate to the button cancel.

<form>
    <input type="number" min="1" max="100" required />
    <input type="submit">Add</input>
    <input type="submit" formnovalidate>Cancel</input>
</form>

这篇关于如何不验证HTML5文本框必需的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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