如何从javascript访问代码中声明的数组

时间:2012-04-16 08:54:48

标签: javascript asp.net code-behind

我的代码如下

Public cs As ClientScriptManager

Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    cs = Page.ClientScript

    cs.RegisterArrayDeclaration("activArray", """asd"",""ert"",""sdt""")

End Sub


//"text/javascript"

function doInit() {

        alert(activArray.length)
}

在运行这些代码时,它显示错误 Microsoft JScript运行时错误:'activArray'未定义

请帮我解决这个错误。谢谢你

1 个答案:

答案 0 :(得分:-2)

只需使用\来转义数组字符串,如:

cs.RegisterArrayDeclaration("activArray", "\"asd\","\"ert\","\"sdt\"")