jquery模拟form表单提交并新打开页面

/**

* form表单提交本页面打开

* @param url

* @param params

*/

functionpostCurrent(url,params){

varform = $("

");

varinput;

form.attr({"action":url});

$.each(params,function(key,value){

input = $("");

input.attr({"name":key});

        input.val(value);

        form.append(input);

    });

$(document.body).append(form);

    form.submit();

}





/**

* form表单提交新打开页面

* @param url

* @param params

*@windowname

*/

functionpostNew(url,params,windowname){

varform = $("

");

varinput;

form.attr({"action":url});

$.each(params,function(key,value){

input = $("");

input.attr({"name":key});

        input.val(value);

        form.append(input);

    });

form.attr({"target":windowname});

window.addEventListener("onsubmit",function(){ openWindow(windowname); });

$(document.body).append(form);

window.dispatchEvent(newEvent("onsubmit"))

    form.submit();

}

functionopenWindow(name)

{

window.open('about:blank',name,'height=400, width=400, top=0, left=0, toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, status=yes');

}



//调用

preview(){

varjson = {

'workStatus': workStatus,

'designNums':this.designNums,

'designModel':this.designModel,

'worksType':this.worksInfo.worksType,

'designUserList':JSON.stringify(designUserList),

'promiseImg1':this.promiseImg1,

'promiseImg2':this.promiseImg2,

'promiseImg3':this.promiseImg3,

'promiseImg4':this.promiseImg4,

'worksInfo':JSON.stringify(worksInfo)

    };

letpostUrl = [[@{/design/showPreviewHtml}]];

    postCurrent(postUrl,json);

}

你可能感兴趣的:(jquery模拟form表单提交并新打开页面)