zoukankan      html  css  js  c++  java
  • asp.net 动态添加JavaScript方法

           //在页面顶部添加脚本
            if (!Page.ClientScript.IsClientScriptBlockRegistered("myscriptKey"))//判断是否已经存在相同//键值的ScriptBlock
            {
                string myScript = @"function AlertHello(){alert('hello xuanhun!!');}";//脚本内容
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "myscriptKey", myScript,true);
            
            }
            //在页面底部添加脚本
            if(!Page.ClientScript.IsStartupScriptRegistered("footscriptkey"))
            {
            string CallScript = @"AlertHello();";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "footscriptKey", CallScript, true);
            }
         // 添加对js文件的引用
            if(!Page.ClientScript.IsClientScriptIncludeRegistered("incluedeKey"))
            {
                string IncludeScript = @"/js/ShowHello.js";
                Page.ClientScript.RegisterClientScriptInclude("includeKey", IncludeScript);
            }


    作者:玄魂
    出处:http://www.cnblogs.com/xuanhun/
    原文链接:http://www.cnblogs.com/xuanhun/ 更多内容,请访问我的个人站点 对编程,安全感兴趣的,加qq群:hacking-1群:303242737,hacking-2群:147098303,nw.js,electron交流群 313717550。
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    关注我:关注玄魂的微信公众号

  • 相关阅读:
    Next Permutation
    SpringMVC配置信息
    Servlet详解(转载)
    Length of Last Word
    Maximum Subarray**
    Divide Two Integers
    Generate Parentheses***
    http解码-2
    编码-1
    扫描工具对比
  • 原文地址:https://www.cnblogs.com/xuanhun/p/1429665.html
Copyright © 2011-2022 走看看