我隐藏了输入值
<input type="hidden" id="as-values-flexmls_connect480723641" class="as-values" value="&MLSAreaMinor=13%20-%20Beachside%26%2344%3B%20N%20of%20Dunlawton%20%26%20S%20Silver,&City=Astor,">
点击表单提交后如何在网址上附加值
所以我当前的网址http://mysite/advanced-search/
然后在<form method="get">
点击提交后获取所有变量然后附加该变量
http://mysite/search/?multiple_get=sdasd&MLSAreaMinor=13%20-%20Beachside%26%2344%3B%20N%20of%20Dunlawton%20%26%20S%20Silver,&City=Astor,
怎么做?我不需要创建隐藏的新输入,因为这只是创建此输入的插件...
我已经有了这个脚本,它从get中删除了空变量,只显示了那个非空变量的URL。
function removeEmptyGetVariables()
{
var myForm = document.getElementById('form-id');
var allInputs = myForm.getElementsByTagName('input');
var input, i;
for(i = 0; input = allInputs[i]; i++) {
if(input.getAttribute('name') && !input.value) {
input.setAttribute('name', '');
}
}
}
答案 0 :(得分:1)
您可以将变量附加到您的终端,然后提交表单,如下所示:
示例:
http://js.do/alvaropaco/append-get-variables-to-url-after-form-submit-without-new-hidden-input
答案 1 :(得分:0)
您可以使用document.ready函数自动更新操作值
$(document).ready(function() {
// Add a hidden value to the form action
var action = $("#my_form").attr("action"),
append = $("input[name=my_input_name]").attr("value");
$("#my_form").attr("action", action + append);
});
为隐藏的输入字段添加名称
<form action="" name="my_form">
<input name="my_input_name" type="hidden" id="as-values- flexmls_connect480723641" class="as-values" value="&MLSAreaMinor=13%20-%20Beachside%26%2344%3B%20N%20of%20Dunlawton%20%26%20S%20Silver,&City=Astor,">
</form>