小编典典

如何在后面的for循环代码中调用javascript?

ajax

protected void Button1_Click(object sender, EventArgs e)
{
    for (int i = 0; i < 100; i++)
    {
        Page.ClientScript.RegisterClientScriptBlock(GetType(), "myScript", "<script>alert('hello world');</script>");
    }
}

警报仅执行一次,是否有可能在迭代中每次执行警报?


阅读 230

收藏
2020-07-26

共1个答案

小编典典

是的,通过将其更改为,请注意“ myScript” + i,它会在每次迭代中更改密钥:

for (int i = 0; i < 100; i++)
        {
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "myScript" + i, "<script>alert('hello world');</script>");
        }
2020-07-26