每次点击页面的按钮时,使用window.location.href=“”时跳转页面地址栏都有参数信息。那么怎么样才能隐藏地址栏参数呢?首先必须自己动态创建一个表单,将表单method改为post,提交这个表单就ok了。
// ===============JavaScript=====================
function postToPage() {
var f=document.createElement('form');
f.style.display='none';
f.action='XXX.do';
f.method='post';
f.innerHTML='<input type="hidden" name="mail" value="'+$("#email").val()+'"/>';
document.body.appendChild(f);
f.submit();
}
// ===============JQuery=====================
function postToPage() {
var form = $("<form>");
form.attr("style","display:none");
form.attr("target","");
form.attr("method","post");
//请求地址
form.attr("action","XXX.do");
var input1 = $("<input>");
input1.attr("type","hidden");
input1.attr("name","path");
input1.attr("value",uploadPath);
$("body").append(form);
form.append(input1);
form.submit();
form.remove();
}