美文网首页
jquery模拟form表单提交并新打开页面

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

作者: smallqiang | 来源:发表于2019-07-26 15:02 被阅读0次

    /**

    * form表单提交本页面打开

    * @param url

    * @param params

    */

    functionpostCurrent(url,params){

    varform = $("<form method='post'></form>");

    varinput;

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

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

    input = $("<input type='hidden'>");

    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 = $("<form method='post'></form>");

    varinput;

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

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

    input = $("<input type='hidden'>");

    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表单提交并新打开页面

          本文链接:https://www.haomeiwen.com/subject/kefdrctx.html