zoukankan      html  css  js  c++  java
  • C#实现动态引用外部的Javascript,CSS

    不多说,贴代码。

    using System;
    using System.Web.UI.HtmlControls;
    namespace webtest
    {
        public partial class Aspx : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                //动态加载javascript
                HtmlGenericControl js = new HtmlGenericControl("script");
                js.Attributes.Add("type", "text/javascript");
                js.Attributes.Add("src", "/Scripts/commonjs.js");
                Page.Header.Controls.AddAt(1, js);
                //动态加载css
                HtmlLink css = new HtmlLink();
                css.Href = "/Styles/site.css";
                css.Attributes.Add("rel", "stylesheet");
                css.Attributes.Add("type", "text/css");
                Page.Header.Controls.AddAt(1, css);
            }
    
        }
    }
    View Code

    动态生成的HTML

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>
    
    </title><link href="/Styles/site.css" rel="stylesheet" type="text/css" /><script type="text/javascript" src="/Scripts/commonjs.js"></script>
            <script type="text/javascript">
                var Request = GetRequest();
                if (Request["id"] != undefined)
                    alert(Request["id"]);
        </script>
    </head>
    <body>
        <div>
            <a onclick="location.href='aspx.aspx?id=3&wo=me'">点击我</a>
        </div>
    </body>
    </html>
    View Code
  • 相关阅读:
    每日总结6.14
    每日总结6.13
    每日总结6.12
    每日总结6.11
    用户故事与敏捷方法阅读笔记4
    用户故事与敏捷方法阅读笔记3
    团队冲刺第一阶段燃尽图
    团队冲刺10
    智能物联网:将人工智能的力量带入物联网
    MyEclipse修改文件后Building workspace时间过长
  • 原文地址:https://www.cnblogs.com/jiangxiaofan/p/3109999.html
Copyright © 2011-2022 走看看