父子頁面交互操作

一、在父界面寫一個JS方法打開並獲取子界面的信息顯示到父界面中:
<script type="text/javascript">
    function OpenNewWindow() {
        //TestBack指要打開的子界面
        var obj = window.showModalDialog("TestBack", window, "dialogHeight =350px;dialogWidth =400px;help=no;status=no;");
        document.getElementById("Productno").value = obj["c1"]["Productno"];
        document.getElementById("Seqno").value = obj["c1"]["Seqno"];
//以下是子界面傳一個值的情況下用
        // document.getElementById("Seqno").value = obj;
    }
</script>
 
單擊某個按鈕調用以上函數:
<input type="button" id="Test" οnclick="OpenNewWindow()" value="Test"  runat="server"/>


二、在子界面中寫一個JS方法傳信息給父界面並關閉窗口:
<script type="text/javascript">
 
        function closeD() {
            //返回一個值
            // window.returnValue = document.getElementById("Productno").value;
            // 返回多個值
            var Productno = document.getElementById("Productno").value;
            var Seqno = document.getElementById("Seqno").value;
            var ht =
            {
                "c1":
                {
                    "Productno": Productno,
                    "Seqno": Seqno
                }
 
            };
 
            window.returnValue = ht;
           
            window.close();
        }
 
    </script>
子界面中單擊某個按鈕調用以上函數:

  <input type="submit" id="serch" value="確定" style="width: 40px; height: 20px; font-size: 11px;" οnclick="closeD()" /><br />


參考網站:

window.showModalDialog的传值和返回值

http://www.blogjava.net/xlth2006/archive/2009/12/15/306065.html


showModalDialog的用法:

http://baike.baidu.com/view/2813452.htm


js 哈希表的几种用法   
http://blog.csdn.net/wcfboy1/article/details/2842678



以下是在MVC3從父窗口單擊表格中的文本框後跳出一個子窗口,並將文本中的內容傳到子窗口被使用(如:多選框時,默認被選中),然後在子窗口做完動作後再將值傳到父窗口的文本中的例子:
1、父窗口:
JS腳本:
    function OpenNewWindow(i) {
        var myObject=document.getElementById(i).value;
        var obj = window.showModalDialog("http://localhost:61981/VendorGrid/docList", myObject, "dialogHeight =350px;dialogWidth =400px;help=no;status=no;");
        if (obj != undefined || obj!=null) {
            document.getElementById(i).value = obj;
        }   
    }

文本框:
<td ><input type="text" value ="@render.HtmlElement(i, "doclist")" name="doclist" id=@i οnclick="OpenNewWindow(@i)" /></td>
                   

2、子窗口:

@model QP.Model.DataWindow.VendorGridArgumentViewModel

           @using QP.Web.Render
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>docList</title>
    <base target="_self">
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.js")" type="text/javascript"></script>
     <script type="text/javascript">
         $(function () {  
             $("#OK").click(function () {
                 var docAll = null;
                 $("input[name=check]").each(function () {
                     if ($(this).attr("checked")) {
                         var doc = $(this).val();
                         if (doc != null) {
                             if (docAll == null)
                                 docAll = doc;
                             else
                                 docAll = docAll + "," + doc;
                         }
                     }

                 });
                 window.returnValue = docAll;
                 window.close();
             });
         });

         function onLoads() {
             var a = window.parent.dialogArguments;
             if (a.length > 0) {
                 var docList = a.split(",");
                 for (var i = 0; i < docList.length ; i++) {
                     docValue(docList[i]);
                 }
             }

         }
         //將已被選擇的信息在此默認勾上
         function docValue(docList) {
             //獲得界面中多選框的個數
             var count = document.getElementById("count").value;
             for (var i = 1; i <= count; i++) {
                 if (document.getElementById(i).checked == false) {
                     var doc = document.getElementById(i).value;
                     if (doc == docList) {
                         document.getElementById(i).checked = true;
                     }
                 }
             }
         }
         function Cancel() {
             window.close();

         }

         /*
        function isOk() {
            //返回一個值
            var docAll = null;
            var count = document.getElementById("count").value;
            for (var i = 1; i <= count; i++)
            {
                //將被選中的內容用,分開放到一個變量中傳到父窗口中
                if (document.getElementById(i).checked == true)
                {
                    var doc = document.getElementById(i).value;
                    if (doc != null)
                    {
                        if (docAll == null)
                            docAll = doc;
                        else
                            docAll = docAll + "," + doc;
                    }
                }
            }
   
            window.returnValue =docAll;
            window.close();
        }
        */
    </script>

</head>
<body οnlοad="onLoads()">
    <div>
        <p>請選擇:</p>
 
        @{
            IEnumerable<QP.Model.DataWindow.VendorGridEntity> list = ViewData["_docList_"] as IEnumerable<QP.Model.DataWindow.VendorGridEntity>;
            if (list != null)
            {
                
                <input type="hidden" id="count" name="count" value=@list.Count() />
            var i = 1;
                foreach (var doc in list)
                {
                    
                   <input type="checkbox" name="check" id=@i value=@doc.Venno >@doc.Venno</input><br/>
                    i=i+1;
                }
            }
        }
    </div>
    <div>
        <input type="submit" id="OK" value="確定" style="width: 40px; height: 20px; font-size: 11px;" />&nbsp;&nbsp;
        <input type="button" value="取消" style="width: 40px; height: 20px; font-size: 11px;" οnclick="Cancel()" />
       </div>                 
</body>
</html>

3、在對應的Controller中打開子窗口的方法

  public ActionResult docList()
        {
            QP.Utils.Web.DalHelper.SafeBox(db =>
            {

                IEnumerable<VendorGridEntity> docList = (from v in db.Load<VendorGridEntity>()
                                                            orderby v.Venno
                                                            select v).Distinct();

               // IEnumerable<VendorGridEntity> docList = db.Load<VendorGridEntity>();此方法一樣可以實現,但是此方法的效率比上面的方法低。
                ViewData["_docList_"] = docList;
                return db.DBI.LastResult;
            });
            return View();
        }                      

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值