form表单的reset
来源:互联网 发布:html中如何加入js类 编辑:程序博客网 时间:2024/05/01 07:08
重置表单(把表单的所有输入元素重置为它们的默认值。):
1.使用reset按钮,条件reset按钮必须在form表单内部。
2. <input id="Button1" type="button" value="button" onclick="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="添 加" CausesValidation="False" OnClientClick="form1.reset();ModalPopup.style.display='';" />
或者
<input id="Button1" type="button" value="button" onclick="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" onsubmit="return(check(this));" onreset="return tips(this);">
....
....
</form>
reture false;表示该事件完成之后,不再交给IE默认处理了,
一般提交按钮的动作是这样:
点击按钮->OnSubmit() ------ return true -> submit()
|
|--->return false 就不往下执行submit()了。
- form表单的reset
- form表单的reset
- 对于Form表单reset方法的误解
- html form表单reset
- 如何用图片实现表单(form)的重置(reset)按钮
- 有初始值的 form 表单元素重置(reset)解决方案
- 如何用图片实现表单(form)的重置(reset)按钮
- jquery实现form表单的submit和reset
- form 表单元素重置(reset)解决方案
- 关于form的reset()方法
- Form Reset
- form表单的提交!!!
- form表单的提交
- Form表单的应用
- form表单的action
- form表单的target
- form表单的target
- Form表单的验证
- HDU 2830 Matrix Swapping II(最大完全子矩阵之可移动列)
- 自由缩放的5z20
- 结构体大小的计算 用最简单的方法,通俗易懂的方法计算结构体大小
- 项目总结——校园开放教育iphone版
- tar命令 (xzvf xjvf)
- form表单的reset
- 学习进度(2012-7-11)(红黑树、多线程、算法分析与设计、COM技术内幕)
- jsp+ext2.0.2分页简单实现
- 西单女孩上春晚的8zsb是什么
- 有关《8zsb》的一些介绍
- Hibernate n+1问题
- Linux SPI框架(下)
- ZOJ3516 Tree of Three,DFS
- [Windows]: 从Windows 7当中引导Ubuntu