showModalDialog 子窗口向父窗口传递数组,js的使用

父窗口代码:

js:

<script language="JavaScript">

        function getProSaleOrder() {
            var vReturnValue = window.showModalDialog('SearchProSaleOrder.aspx', window, 'dialogWidth=900px;dialogHeight=500px;status=no');

            if (vReturnValue !== "" && vReturnValue !== undefined) {
                document.getElementById("receipBillCode").value = vReturnValue[0];
                document.getElementById("busiName").value = vReturnValue[1];
                document.getElementById("shouReciAmount").value = vReturnValue[2];
            }
        }
      </script>

调用js的地方:

<image   src="../Images/search.png"  onclick="getProSaleOrder(document.all.receipBillCode)";  style="CURSOR: hand"  alt="请查找" >

子窗口代码:

js:

<script language="JavaScript">

        function returnSelect() {
            var retArr = new Array();
            retArr[0] = arguments[0];
            retArr[1] = arguments[1];
            retArr[2] = arguments[2];
            window.returnValue = retArr;

            window.close();
        }
    </script>

 

 

 子窗口的后台事件中调用该js的地方:

 //GridView1_RowDataBound事件   双击返回值
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#9CCBF7';this.style.cursor='hand'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

            //注意格式,是单引号加双引号,否则会提示“常量中有换行符”
            //string[] sel = { e.Row.Cells[0].Text.ToString(), e.Row.Cells[1].Text.ToString(), e.Row.Cells[2].Text.ToString() };
            //Response.Write(sel[0]);
            //e.Row.Attributes.Add("ondblclick", "returnSelect(sel);");
            e.Row.Attributes.Add("ondblclick", "returnSelect( '" + e.Row.Cells[0].Text.ToString() + "','" + e.Row.Cells[1].Text.ToString() + "','" + e.Row.Cells[2].Text.ToString() + "')");
          
        }

    }

 

注意这里传递数组的方法:js函数returnSelect()里面并没有参数,获得数组是在函数里面获得的,后台传值的时候也是直接罗列的。

 

 

 

 

原来我按照自己的思路是这么做的:

js:

<script language="JavaScript">

        function returnSelect(retArr) {
                      window.returnValue = retArr;

            window.close();
        }
    </script>

后台调用传值:

 //GridView1_RowDataBound事件   双击返回值
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#9CCBF7';this.style.cursor='hand'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

            
            string[] sel = { e.Row.Cells[0].Text.ToString(), e.Row.Cells[1].Text.ToString(), e.Row.Cells[2].Text.ToString() };
            
            e.Row.Attributes.Add("ondblclick", "returnSelect(sel);");
           
          
        }

    }

这里我按照c#的编程方法想当然的传递参数,结果js里面提示错误“"retArr"未定义”

posted on 2012-06-14 01:30  初学者心态 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/jinianjun/archive/2012/06/14/2548718.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值