js - 表单提交的几种方式

1,581 阅读1分钟

直接使用form表单提交

  1. 使用表单action属性
    提交的地址直接写在form表单的action属性中
    ''' html <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Insert title here</title> </head> <body> <form action="http://localhost:8080/user" method="post"> username:<input type="text" name="username" /><br>

    password:<input type="password" name="password" /> <br>

    <input type="submit" value="登录"> </form> </body> </html> '''

使用ajax提交

  1. form表单中使用<input type="button" onclick="mySubmit">提交,在mySubmit中使用ajax获取元素数据,使用ajax提交到远程服务器。
  2. form表单中使用<input type="submit">促发表单的提交,input的type必须为submit
  3. form表单中使用<form onsubmit="mySubmit">促发表单提交,input的type必须为submit。mySubmit函数返回true时提交到远程服务器,false不提交到远程服务器。

blog.csdn.net/a1194821568…
blog.csdn.net/weixin_4238…