喜欢的代码
在.cs页面
string test = "1,2";
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script", "OpenCenterWindow(" + test + ");", true);
JavaScript 函数
function OpenCenterWindow(Ids) {
alert(Ids);
}
在上面我得到了 alert box = 1
我已经尝试使用加密和解密,但我收到类似 Uncaught SyntaxError: Unexpected token 的错误) OpenCenterWindow(fBqJaxPUucc=);
但我想要 1,2 任何解决方案?
最佳答案
像下面这样使用
string test = "1,2";
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script",
"OpenCenterWindow('" + test + "');", true);
您需要在单引号'
或双引号"
编辑1
当你调用一个函数时,如果你必须传递一个静态值,你总是在 javascript 中使用 '
或 "
。
关于javascript - 如何从后面的代码传递 JavaScript 函数中的逗号分隔字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25842775/