JavaScript表单提交四种方式

总结JavaScript表单提交四种方式

<!DOCTYPE html>
<html>
  <head>
    <title>JavaScript表单提交四种方式</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript" >
        function submit1()//第二种提交方式,用普通button按钮结合JavaScript提交
        {
            var form1=document.getElementById("form1");
            form1.action="2.html";                //设置提交路径
            form1.submit();                            //提交
        }
    </script>
  </head>
  <body>
      <!-- 第一种提交方式也是最普遍的提交方式 -->
      <form action="2.html">          
          用户名:<input type="text" value="1234" name="username">
          <input type="submit" value="submit提交">
      </form>
      <hr>
      <!-- 第二种提交方式,用普通button按钮结合JavaScript提交-->
      <form id="form1">          
          用户名:<input type="text" value="1234" name="username">
          <input type="button" value="普通button结合JavaScript提交" onclick="submit1();">
      </form>
      <hr>
      <!-- 第三种提交方式,用图片提交-->
      <form action="2.html">          
          用户名:<input type="text" value="1234" name="username">
          <input type="image" src="fmy.jpg" width="50px" height="50px">
      </form>
      <hr>
      <!-- 第四种提交方式,超链接提交,直接把表单内容写在链接中,几乎没人用-->
      <a href="2.html?username=1234">超链接提交,直接把表单内容写在链接中,几乎没人用</a>
  </body>
</html>

运行示意:

 

posted @ 2016-10-12 13:35  凌晨。。。三点  阅读(8774)  评论(0编辑  收藏  举报