HTML 5在表单上的所有按钮上都需要验证器触发器

编程入门 行业动态 更新时间:2024-10-27 08:31:26
本文介绍了HTML 5在表单上的所有按钮上都需要验证器触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 <asp:TextBox ID="txtCompanyName" runat="server" placeholder="Company Name" BorderColor="#C2C4CC" BorderStyle="Solid" Height="28px" Width="135px" title="Enter Company Name" BackColor="#F9E3CB" Enabled="False" TabIndex="7" required></asp:TextBox>

以下是我的一个带有required属性的文本框的标记。

Here is the mark up for one of my textbox with the "required" attribute.

我的问题是,我的表单上有3个按钮,取消,重置和提交按钮。 html5必需的验证器只应在单击提交按钮时触发。但是,即使我按下取消和重置按钮,它仍然会触发。

My question is, I have 3 buttons on my form, cancel, reset and submit button. the html5 required validator should only trigger when the submit button is clicked. however, it still triggers even if I press cancel and reset buttons.

如何只在一个按钮上分配html 5必需的验证器?

How can I assign html 5 required validator on only one button?

这是我的按钮的标记:

取消按钮:

<asp:ImageButton ID="Cancel" runat="server" ImageUrl="~/Images/ClaimForm/btnCancel.gif" OnClick="btnFallBack_Click" Visible="False" ToolTip="Cancel" draggable="false" />

重置按钮:

<asp:ImageButton ID="btnClear" runat="server" OnClick = "OnConfirm" OnClientClick = "Confirm()" ImageUrl="~/Images/ClaimForm/Clear.jpg" draggable="false"/>

提交按钮

<asp:ImageButton ID="btnNext" runat="server" ImageUrl="~/Images/ClaimForm/submitbutton.jpg" draggable="false" OnClick="btnNext_Click"/>

推荐答案

我通过为该按钮分配onclick功能解决了这个问题并添加:

I solved it by assigning an onclick function to that button and adding:

event.preventDefault();

更多推荐

HTML 5在表单上的所有按钮上都需要验证器触发器

本文发布于:2023-11-12 04:58:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580571.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:触发器   上都   表单   按钮   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!