![.NET提供了三种后台输出js的方式: .NET提供了三种后台输出js的方式:](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
.NET提供了三种后台输出js的方式:
首先创建 js文件testjs.js
{
Page.ClientScript.RegisterClientScriptInclude("keys", "testjs.js");
}
string scriptstrs = "";//此处只作为演示,如代码需多次拼接应采用StringBuilder方式
scriptstrs += "function test(str)";
scriptstrs+="{alert(str);}";
if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "keys"))
{
三、 输出一次性使用的js代码
if (!Page.ClientScript.IsStartupScriptRegistered(this.GetType(),"welcome"))
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "welcome", scriptstrs);
}