前言
不使用<button type="submit"></button>
标签,也不使用<input type="submit">
标签,提交表单的方法
提交表单
- html代码
- 必须定义name属性,因为会根据name属性向后端发送请求
1 2 3 4 5 6 7 8
| <form id="formId"> <div class="form-group"> <label>标题:</label> <input type="text" name="title" id="titleId"> </div> </form>
<button type="button" onclick="doSave()">确定</button>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| function doSave() { let url=""; let params = $("#formId").serialize(); $.ajax({ type:"post", url:url, data:params, success:function(result){ console.log(result); } }); }
|
完成