(一),js的写法,通过js的各种选择器,实现表单提交提交
/*frm为某个表单form的id*/
var fr = document.getElementById('frm');
fr.action = "DeptDeleteServlet";
fr.method = "post";
fr.submit();
/*表单重置*/
document.getElementById("frm").reset();
(二)、Jquery实现表单提交
$("#frm").attr("methord","post");
$("#frm").attr("action","tkgd/updatetTicketGrade.action");
$('#frm').submit();
/*表单的重置*/
$('#frm').reset();
/*无效,,,,无效,jquery没有直接的reset方法*/
/*要这样来哦*/
/*也就是通过调用 DOM 中的reset方法来重置表单。
因为Form表单元素自带reset()方法啦*/
$('#frm')[0].reset()
(三)特殊情况
/* 当触发js提交表单的元素位于form外时*/
/*可以提交*/
<form action="" method="post" id="frm">
</form>
<input type="button" value="重 置" id="reset" />
<input type="button" value="增 加" id="submit" />
/* 当触发js提交表单的元素位于form内部*/
/*无法触发js事件*/
/*不管用js还是,jquery的选择器*/
<form action="" method="post" id="frm">
<input type="button" value="重 置" id="reset" />
<input type="button" value="增 加" id="submit" />
</form>
(四)jquery js 重置表单 reset()具体实现代码
在开发中,我们会用到很多表单,我们希望表单提交以后,能reset,
但是jquery没有这个方法,怎么处理呢?
<form id="form1" action="" method="post" runat="server">
<input name="inp" id="inp" value="1" />
</form>
方法一:
我们可以通过就是实现
id:
document.getElementById("form1").reset();
name:
document.formName.reset();
方法二:
逐一清空:
$("#inp").val("1");
但是表单太多的话,这也是不实际的,有100个,1000个,总不能写100,个1000个吧。
也许你会说,写成这样:
$("input").val("");
那表单的默认值呢?表单还有其他类型,都写一遍?
加type为reset的input
<form id="form1" action="" method="post" runat="server">
<input name="inp" id="inp" value="1" />
<input id="res" name="res" type="reset" style="display:none;" />
</form>
$("input[name='res']").click();
所有表单清空