ASP.NET provides three ways to output JS in the background: 1. There is already a js file in the background output Start by creating a js file testjs.js
if (! Page.Clientscrip removes t.IsClientscrip removes tIncludeRegistered(this. GetType(), "keys"))) // to determine if the keys are registered
{ Page.Clientscrip removes t.RegisterClientscrip removes tInclude("keys", "testjs.js");
} 2. Output the js code block string scrip remove tstrs = ""; This is for demonstration only, if the code needs to be spliced multiple times, the StringBuilder method should be used scrip removes tstrs += "function test(str)"; scrip remove tstrs+="{alert(str); }"; if (! Page.Clientscrip removes t.IsClientscrip removes tBlockRegistered(this. GetType(), "keys"))
{ Page.Clientscrip removed t.RegisterClientscrip removed tBlock(this. GetType(), "keys", scrip remove tstrs, true);
} 3. Output the disposable js code
string scrip remove tstrs = "<scrip去掉t>alert('Welcome!' ); </scrip去掉t>"; if (! Page.Clientscrip removes t.IsStartupscrip removes tRegistered(this. GetType(),"welcome")) { Page.Clientscrip removed t.RegisterStartupscrip removed t(this. GetType(), "welcome", scrip remove tstrs); } In addition, use Response.Write("<scrip去掉t>alert('ww'); </scrip去掉t>"); You can also output simple js code, but I personally don't advocate this method. Because in the previous development, there were some cases where this method would cause the page font size to change after the prompt message pops up, so it is recommended to use the above three methods for safety reasons.
|