本文介绍了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在表单上的所有按钮上都需要验证器触发器
发布评论