我需要在 javascript 警报弹出窗口中一一显示所有字符串值。但我的代码不工作。我的代码看起来像:
<script type="text/javascript">
function test(x)
{
for(var i = 0; i<x.length; i++)
{
alert(x[i]);
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btn" runat="server" Text="Submit" onclick="btn_Click" />
</div>
C# code:
protected void btn_Click(object sender, EventArgs e)
{
string [] str=new string[5];
str[0] = "string1";
str[1] = "string2";
str[2] = "string3";
str[3] = "string4";
str[4] = "string5";
btn.Attributes.Add("onclick", "javascript:test(str);");
}
如何解决这个问题呢 ?