zoukankan      html  css  js  c++  java
  • 如何在一个form表单中实现多个submit

    As we all know,通过设置input type=“submit”,我们可以把form表单中的值通过post方式传递给action所指向的页面。下图中,我们可以把userName,userAge,userSex这三个值传递到xxx.jsp

    <form action="xxx.jsp" method="post">
                <input type="text" name="userName"/>
                <input type="text" name="userAge"/>
                <input type="text" name="userSex"/>
    </form> 

    但是,有些情况下(大家可能会遇到),需要在同一个form中使用两个或多个submit,当然,这在语法上是不行的,怎么办呢,我们可以通过javascript来实现。此时,from表单的写法也有些变化——(1)增加一个name属性,(2)把action属性去掉,(3)使用类型为button的input标签。 

    <form name="frm" method="post">
                <input type="text" name="userName"/>
                <input type="text" name="userAge"/>
                <input type="text" name="userSex"/>

                <input type="button" name=" value="第一个提交" />
                <input type="button" name="value="第二个提交" />
    </form> 

    接着,写javascript代码

    <script>

                 function act1(){

                           document.frm.action="xxx1.jsp";

                           document.frm.submit();   

    }

                 function act2(){

                           document.frm.action="xxx2.jsp";

                           document.frm.submit();   

    }

    </script>

    然后在button里添加onclick事件

     

    <form name="frm" method="post">
                <input type="text" name="userName"/>
                <input type="text" name="userAge"/>
                <input type="text" name="userSex"/>

                <input type="button"  onclick="act1()"  value="第一个提交" />
                <input type="button"  onclick="act2()"   value="第二个提交" />
    </form> 

    至此完毕。

  • 相关阅读:
    Eclipse安装Git插件及简单操作
    物联网架构成长之路(28)-Docker练习之MQ中间件(Kafka)
    版本分支管理标准
    社交的基本逻辑
    委托投资方案
    印钞机 V1.0(量化选基总结)
    中小研发团队架构实践之总体架构设计
    FOF 全面科普贴(转载)
    DUIR Framework 相关技术介绍
    使用融资的心得和教训
  • 原文地址:https://www.cnblogs.com/tytr/p/5897331.html
Copyright © 2011-2022 走看看