我在页面上有很多类似以下的表单。现在我想根据用户点击哪个提交按钮来更改表单操作(并且当然要提交表单)。
<form action="/shop/products.php" data-ajax="false" method="post">
<div data-role="fieldcontain">
<input name="submit" class="obutn" type="submit" value="Order" />
<input name="submit" class="oEbutn" type="submit" value="Extras" />
</div>
</form>
我尝试使用
$(".obtn").click(function() {
$(this).parent().parent().attr("action", "/shop/products.php");
});
$(".oEbtn").click(function() {
$(this).parent().parent().attr("action", "/shop/extras.php");
});
但表单始终会提交到products.php。你能告诉我问题出在哪里吗?
action
属性,而是考虑在每个单独的input
元素上设置formaction
属性。文档:http://www.w3.org/TR/html-markup/input.submit.html#input.submit.attrs.formaction - xorcus