在表单提交之前更改URL

时间:2015-01-08 08:32:32

标签: javascript jquery

HTML

<form id="form" method="post" action="/create_test1/54ae2be44a1bfef3138b4569">
.
.
.
<input type="button" id="export" value="Export">
</form>

的jQuery

$("#export").click(function(){
  url = $("#form").attr("action");
  url = url.replace("create_test1","export_test1"); // This is OK
  $('#form').attr('action', url).submit();  //Here form is not submited
});

实际网址:/ create_test1 / 54ae2be44a1bfef3138b4569

我想要网址:/ export_test1 / 54ae2be44a1bfef3138b4569

我的问题是如何在更改行动后提交表格?

1 个答案:

答案 0 :(得分:1)

 $("#export").click(function()
{
 $('#form').attr('action', '/export_test1/54ae2be44a1bfef3138b4569'); 
});