0

我想同时提交一个表单并重写 url。onsubmit="rewrite_form(event);"我可以通过在表单中​​添加选项来更改 url :

function rewrite_form(e) {    
  var form = document.forms[0];   // .getElementById("form1");
  window.location = '/search/' + form.f.value + '_' + form.t.value + '.htm/' + form.amt_from.value;            
  if (e && e.preventDefault) { e.preventDefault(); }
  return false;
}

网址更改,但表单的其他值未发布到 url 生成的页面。

4

2 回答 2

0

只需更改表单的操作属性即可。

function rewrite_form(e) {
    var form = documen.forms[0];

    form.action = 'newurl';
    //rest of code, make sure not to call e.preventDefault(); or return false
    //because the form will not get submitted
}
于 2013-11-04T04:59:50.847 回答
0

我得到了解决方案:

    function rewrite_form() {
//Create custom link here
----------------------------
----------------------------------
//create form submit action
var url = '/search/' +'your custom link';
document.getElementById('FormId').action = url;
document.FormId.submit();
}
于 2013-11-04T06:37:57.793 回答