代码
在.cs页面
string test = "1,2";
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script", "OpenCenterWindow(" + test + ");", true);
JavaScript功能
function OpenCenterWindow(Ids) {
alert(Ids);
}
在上面我得警报框= 1
我尝试使用Encrypt和Decrypt但是我收到的错误就像Uncaught SyntaxError:Unexpected token) OpenCenterWindow(fBqJaxPUucc =);
但我想1,2 任何解决方案
答案 0 :(得分:1)
你可以这样做:
string test = "[1,2]";
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script", "OpenCenterWindow(" + test + ");", true);
因此,您将在客户端获得一个整数数组:
function OpenCenterWindow(myArray) {
alert(Ids);
}
答案 1 :(得分:1)
使用如下
string test = "1,2";
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script",
"OpenCenterWindow('" + test + "');", true);
您需要以单引号'
或双引号"
传递值
当您调用某个函数时,如果必须传递静态值,则始终在javascript中使用'
或"
。
答案 2 :(得分:0)
检查这项工作。
<script>
ids="1,2";
function OpenCenterWindow(Ids) {
alert("herer");
alert(Ids);
}
OpenCenterWindow(ids);