今天做个项目,在form表单中action存在多种走向
我们可以通过ajax实现,但是我们也可以通过js来做
- <mce:script type="text/javascript"><!--
- function insertStu(){
- document.getElementById('myForm').action = "ctl.jsp?op=insert";
- document.getElementById("myForm").submit();
- }
- function deleteStu(){
- document.getElementById('myForm').action = "ctl.jsp?op=delete";
- document.getElementById("myForm").submit();
- }
- function modifyStu(){
- document.getElementById('myForm').action = "ctl.jsp?op=modify";
- document.getElementById("myForm").submit();
- }
- function selectStu(){
- document.getElementById('myForm').action = "ctl.jsp?op=select";
- document.getElementById("myForm").submit();
- }
- t;</mce:script>
<form id="myForm" action="" method="post">
<input type="button" name="qurray" value="查询" οnclick="selectStu()" />
<input type="button" name="updata" value="修改" οnclick="modifyStu()" />
<input type="button" value="添加" οnclick="insertStu()" />
<input type="button" name="del" value="删除" οnclick="deleteStu()" />
</form>
==========================================================
也可以把js语句直接写在input按钮的 onclick 里:
<form name="form1" action="">
<input type="button" value="action1" οnclick="form1.action='1';form1.submit();">
<input type="button" value="action2" οnclick="form1.action='2';form1.submit();">
</form>