HTML表单 - POST或GET取决于点击的按钮
问题描述:
让我们来看一个包含很多输入字段的搜索表单。用户既可以点击:HTML表单 - POST或GET取决于点击的按钮
- [查询],并得到结果的列表,
- [保存搜索条件]以供将来使用和POST形式的内容存储在服务器上(我不感兴趣在本地存储Cookie等)。
我该如何做到这一点?我只找到解决方案在两个单独的按钮上创建两种类型的POST请求。
也许JavaScript onclick函数在提交之前设置<form method="??">
?这会起作用吗?
答
在HTML5中,<input>
元素得到some new attributes
<input type="submit" formmethod="post" formaction="save.php" value="Save" />
<input type="submit" formmethod="get" formaction="search.php" value="Search" />
相同的属性是valid for <button>
答
是的,你可以改变形式的方法之前使用jQuery
<form method="POST" id="myForm">
<button onclick="changeMethod()">submit</button>
</form>
功能changeMethod jQuery的提交表单
function changeMethod(){
$("#myForm").attr("method", "get");
}
+0
为什么给你的例子与jQuery? –
所以你已经有了你的概念。跟着它! – Zim84