form表单的reset

form表单的reset
 

重置表单(把表单的所有输入元素重置为它们的默认值):

1.使用reset按钮,条件reset按钮必须在form表单内部。

2. <input id="Button1" type="button" value="button" οnclick="form1.reset();" />可以不在表单内部。

用途示例:一般我们做添加页面和编辑页面时用的都是同一个页面,这样以来编辑后再添加时表单内容就需要清除,很多人在使用后台代码做清除工作如:

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            lblCaption.Text = "添加";
            ArticleType1.ddlTypeEnabled = false;
            ArticleNoImg.txtTitleText = "";
            ArticleNoImg.fckContentText = "";
            ArticleType1.ddlTypeSelectValue = articleTypeId;
            lblUpFileName.Visible = false;
            lblDocFileName.Visible = false;
            lblNotice.Visible = false;
            imgBtnDelete.Visible = false;
             ......
            SelectedId = "";

            ModalPopup.Show();
        }

实际上我们可以更简单些,使用js脚本来实现:

<asp:Button ID="btnAdd" runat="server" Text="添&nbsp;&nbsp;加" CausesValidation="False" OnClientClick="form1.reset();ModalPopup.style.display='';" />

或者

<input id="Button1" type="button" value="button" οnclick="form1.reset();ModalPopup.style.display='';" />

另外:

有些项(下拉框、复选列表、单选列表)我们只要有默认值,reset并不会把它们清除掉,而是自动设置成默认项。

    <asp:TextBox ID="TextBox1" runat="server">aaa</asp:TextBox>

    <asp:CheckBoxList ID="CheckBoxList1" runat="server">
        <asp:ListItem>aaa</asp:ListItem>
        <asp:ListItem Selected="True">bbb</asp:ListItem>
        <asp:ListItem Selected="True">ccc</asp:ListItem>
    </asp:CheckBoxList>

    <asp:RadioButtonList ID="RadioButtonList1" runat="server">
        <asp:ListItem Selected="True">aa</asp:ListItem>
        <asp:ListItem>bb</asp:ListItem>
        <asp:ListItem>cc</asp:ListItem>
    </asp:RadioButtonList>

    <asp:DropDownList ID="DropDownList1" runat="server">
        <asp:ListItem>aa</asp:ListItem>
        <asp:ListItem>bb</asp:ListItem>
        <asp:ListItem Selected="True">cc</asp:ListItem>
    </asp:DropDownList>
    <asp:ListBox ID="ListBox1" runat="server">
        <asp:ListItem>a</asp:ListItem>
        <asp:ListItem Selected="True">b</asp:ListItem>
        <asp:ListItem>c</asp:ListItem>
    </asp:ListBox>

onsubmit,onreset的用法:

<script type="javascript">
function check(theform)

      这里写你要检查一些输入是否合法 
      如果合法就提交表单,去执行你的下个页面(uurl) 
      如果不合法就return false;这样就不提交页面
}
function tips(theform)
{
    表单重置会清空当前内容,您确定要重置表单吗?

}
</script>
<form name="form1" action="uurl" οnsubmit="return(check(this));" οnreset="return tips(this);">
....
....
</form> 

reture false;表示该事件完成之后,不再交给IE默认处理了,
一般提交按钮的动作是这样:
点击按钮->OnSubmit() ------ return true -> submit()
|
|--->return false 就不往下执行submit()了。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值