自己对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>
<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>
<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>");
其实很简单,不过网上写的这么详细的很少啊。