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>"); } }
警报仅执行一次,是否有可能在迭代中每次执行警报?
是的,通过将其更改为,请注意“ myScript” + i,它会在每次迭代中更改密钥:
for (int i = 0; i < 100; i++) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "myScript" + i, "<script>alert('hello world');</script>"); }