Js生成表单使用post提交方式带参数下载文件,页面不跳转
postFile(params, url) { var form = document.createElement("form"); form.style = "display:none;"; form.action = url; form.method = "post"; form.target = "form_iframe" document.body.appendChild(form); if(!document.getElementById("form_iframe")){ var ifreame = document.createElement("iframe") ifreame.id = "form_iframe"; ifreame.name = "form_iframe"; ifreame.style ="display:none;" document.body.appendChild(ifreame); } // 动态创建input并给value赋值 for (var key in params) { var input = document.createElement("input"); input.type = "hidden"; input.name = key; input.value = params[key]; form.appendChild(input); } form.submit(); form.remove(); } },