1. 程式人生 > >jquery $.jBox彈窗 父窗體呼叫子窗體方法,儲存子窗體頁面資料

jquery $.jBox彈窗 父窗體呼叫子窗體方法,儲存子窗體頁面資料

//新增--以彈窗的方式                                父窗體

<script type="text/javascript"> $(document).ready(function() {

$("#btnAdd").click(function () {

                $.jBox.open("iframe:${ctx}/xxx/xxx/form/", "監察使用者機構管理新增", 600, 300, {           //如果是修改,傳個ID就行了                     buttons: {"確定": "ok", "關閉": true},submit: function (v, h, f) {                         if (v == "ok") {                             var iframeName = h.children(0).attr("name");                             var iframeHtml = window.frames[iframeName];               //獲取子視窗的控制代碼                             iframeHtml.saveOrUpdate();                             return false;                         }                     },                     loaded: function (h) {                         $(".jbox-content", document).css("overflow-y", "hidden");                     }                 });             });  

});

</script>

//子窗體

<script type="text/javascript">                function saveOrUpdate(){                                      //子窗體頁面的儲存資料方法 通過ajax             if($("#inputForm").valid()){                 var url = "xx/xx/xx/save";                 $.ajax({                     type: 'POST',                     url : url,                     data: $('#inputForm').serialize(),             //獲取表單資料                     success : function(data) {                         if (data.success) {                             alert("儲存成功");                             window.parent.page();                                     //呼叫父窗體方法,當關閉子窗體重新整理父窗體                             window.parent.window.jBox.close();            //關閉子窗體

                        } else {                             alert("儲存失敗:"+data.message);                             window.parent.page();                             window.parent.window.jBox.close();                         }                     }                 });             }         } </script>

<body>

//Form 表單

<form:form id="inputForm">

</form:form>

</body> ---------------------  作者:後青春期的小白  來源:CSDN  原文:https://blog.csdn.net/aisubingbing/article/details/26845767?utm_source=copy  版權宣告:本文為博主原創文章,轉載請附上博文連結!