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

 

相关文章:

  • 2021-05-18
  • 2022-12-23
  • 2021-10-30
  • 2021-07-14
  • 2021-06-14
  • 2021-06-04
  • 2021-05-28
猜你喜欢
  • 2021-11-11
  • 2022-02-27
  • 2022-12-23
  • 2022-01-15
  • 2022-03-07
  • 2021-11-11
相关资源
相似解决方案