JS提交表单页面不跳转、JS下载、动态创建from
作者:互联网
JS下载
function downloadFile(id) { var url = "<%=request.getContextPath()%>/cer/downloadFile"; var form = $("<form></form>").attr("action", url).attr("method", "post"); form.append($("<input></input>").attr("type", "hidden").attr("name", "fileId").attr("value", id)); form.appendTo('body').submit().remove();//提交之后再删除from表单 }
动态创建from,提交表单
jForm.appendTo('body') function loadPage(url, projectName) { var jForm = $('<form></form>', { action: url, method: 'post' }); $("<input>", { name: 'curPrj', value: projectName }).appendTo(jForm); jForm.appendTo('body').submit(); } var form = $("<form method='post'></form>"), input; form.attr({ "action": url }); $.each(args, function (key, value) { input = $("<input type='hidden'>"); input.attr({ "name": key }); input.val(value); form.append(input); }); form.appendTo('body').submit();
标签:body,attr,form,url,动态创建,JS,appendTo,跳转,input 来源: https://www.cnblogs.com/hnsongbiao/p/11068229.html