.NET提供了三种后台输出js的方式:

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

 

萌橙 你瞅啥?
原文地址:https://www.cnblogs.com/daimaxuejia/p/7443937.html