如何调用JavaScript在背后环code?JavaScript、code

2023-09-10 17:05:14 作者:牵挂总是想想想不见

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>");
    }
}

警报只执行一次,是可以执行的警报在每次迭代?

The alert only execute once, is that possible to execute the alert everytime in the iteration?

推荐答案

是通过其更改为,注意myScript的+ I,它改变了关键的OM每次迭代:

yes by changing it to, note the "myScript" + i, it changes the key om every iteration:

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