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> 

    至此完毕。

  • 相关阅读:
    第六章 条件处理
    VS2019配置MKL教程(Windows)
    攻防世界--srm-50
    攻防世界--The_Maya_Society
    攻防世界--re1-100
    BUUCTF--findit
    凯撒加密与解密实现
    BUUCTF--rsa
    正则表达式
    PyQuery详解
  • 原文地址:https://www.cnblogs.com/tytr/p/5897331.html
Copyright © 2011-2022 走看看