ClientScript.RegisterStartupScript的用法?
发布网友
发布时间:2022-04-20 20:03
我来回答
共1个回答
热心网友
时间:2023-06-30 01:23
如何使用clientscript.registerstartupscipt
RegisterStartupScript的参数key值重复的话,只有注册的第一次才有效。
可以改成:
if (!IsPostBack) {
int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
foreach (int i in array) {
ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript"+i, "<script>run(" + i + ")</script>");
}
}
或者:
if (!IsPostBack) {
int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
foreach (int i in array) {
ClientScript.RegisterStartupScript(ClientScript.GetType(), Guid.NewGuid().ToString(), "<script>run(" + i + ")</script>");
}
}
其实这样写也没有意义,你要循环执行run函数的话,
可以只注册一次,比如 doRun(30),然后在js函数里面循环去调用。