showModalDialog返回数组

自己对js可真是不熟悉啊。一个返回数组问题居然难了我一个下午,为了防止再次忘记 还是把它写下来吧。

页面Default.aspx代码如下

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>

    <script language="javascript" type="text/javascript">
  
    function DispModelDialog()
    {
  
     var a=new Array(3);
     a= showModalDialog("Default2.aspx",a,"status:no;Help:no;resizable:yes");
     document.form1.TextBox1.value=a[0];
     document.form1.TextBox2.value=a[1];
     document.form1.TextBox3.value=a[2];
    
    }
 
    </script>

</head>
<body>
    <form id="form1" runat="server">
        <div>
            &nbsp;<table>
                <tr>
                    <td style="width: 100px">
                        姓名:</td>
                    <td style="width: 100px">
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
                    <td style="width: 100px">
                        <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="DispModelDialog();" /></td>
                </tr>
                <tr>
                    <td style="width: 100px">
                        类型:</td>
                    <td style="width: 100px">
                        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
                    <td style="width: 100px">
                    </td>
                </tr>
                <tr>
                    <td style="width: 100px">
                        号码:</td>
                    <td style="width: 100px">
                        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td>
                    <td style="width: 100px">
                    </td>
                </tr>
            </table>
        </div>
        <input id="Button2" type="button" value="button" οnclick="DispModelDialog();" />
    </form>
</body>
</html>
Default2.aspx

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title><base target="_self" />
    <script language="javascript" type="text/javascript">
    var name="123";
    function funGetInfo()
    {  
    var sDate=new Array(3);
    sDate[0]=document.form1.TextBox1.value;
    sDate[1]=document.form1.TextBox2.value;
    sDate[2]=document.form1.TextBox3.value;
    window.returnValue= sDate;   
    window.close();
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:TextBox ID="TextBox1"  runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2"  runat="server"></asp:TextBox>&nbsp;&nbsp;
        <asp:TextBox ID="TextBox3"   runat="server"></asp:TextBox>
          <input id="Text1" type="text" /> 
        <input id="Button2" type="button" value="button" οnclick="funGetInfo();"/>
    </form>
</body>
</html>

可以在服务器端输出javascript比如在一个包含gridview的页面上,你过你需要选择一行数据中的3个值返回

你就可以这样写了

        Response.Write("<script language=javascript> var s=Array(3);s[0]='"+this.GridView1.SelectedRow.Cells[0].Text+"';"+
        "s[1]='"+this.GridView1.SelectedRow.Cells[1].Text+"';s[2]='"+this.GridView1.SelectedRow.Cells[2].Text+"';window.returnValue=s;window.close();</script>");

其实很简单,不过网上写的这么详细的很少啊。
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值