• 将js文件编译成动态链接库(dll)文件


    1.向项目中添加Jscript文件

    //script_1.js-----
    function doClick1()
    {
        alert("OK1_wufeng");
    }
    //script_2.js-----
    function doClick2()
    {
        alert("OK2");
    }

    2.解决方案资源管理器中,右键查看script_1.js和script_2.js的属性,把高级中的“生成操作”属性设置成“嵌入的资源”。

    3.向AssemblyInfo.cs文件中添加如下行:(注意域名wf.ClientScriptResourceLabel)

    [assembly: System.Web.UI.WebResource("wf.ClientScriptResourceLabel.script_1.js", "application/x-javascript")]
    [assembly: System.Web.UI.WebResource("wf.ClientScriptResourceLabel.script_2.js", "application/x-javascript")]

    4.向项目中添加一个类, 实例:

    using System;
    using System.Drawing;
    using System.Web.UI;
    using System.Web;
    using System.Globalization;

    namespace wf.ClientScriptResourceLabel
    {
        public class ClientScriptResourceLabel : System.Web.UI.WebControls.WebControl
        {
            //调用脚本资源
            protected override void OnPreRender(EventArgs e)
            {
                if (this.Page != null)
                {
                    this.Page.ClientScript.RegisterClientScriptResource(typeof(ClientScriptResourceLabel), "wf.ClientScriptResourceLabel.script_1.js");
                    this.Page.ClientScript.RegisterClientScriptResource(typeof(ClientScriptResourceLabel), "wf.ClientScriptResourceLabel.script_2.js");
                }
                base.OnPreRender(e);
            }

            /// <summary>
            /// 呈现控件的方法RenderContents
            /// </summary>
            protected override void RenderContents(HtmlTextWriter output)
            {
                output.AddAttribute("id", "1");
                output.AddAttribute("type", "checkbox");
                output.AddAttribute("value", "测试1");
                output.AddAttribute("onclick", "javascript:doClick1();");
                output.RenderBeginTag(HtmlTextWriterTag.Input);
                output.RenderEndTag();

                output.AddAttribute("id", "2");
                output.AddAttribute("type", "checkbox");
                output.AddAttribute("value", "测试2");
                output.AddAttribute("onclick", "javascript:doClick2();");
                output.RenderBeginTag(HtmlTextWriterTag.Input);
                output.RenderEndTag();

                base.RenderContents(output);
            }
        }
    }

    文章来自: 好喜爱学习网(http://www.haoxiai.net/) 网址:http://www.haoxiai.net/wangzhanzhizuo/JavaScript/48728.html

  • 相关阅读:
    高中数学相关的专业术语
    数学-高数2
    python+unittest+xlrd+request搭建API测试框架
    接口自动化,断言方法,深度定位错误
    python+requests+unittest API接口测试
    python+unittest框架整理(一点点学习前辈们的封装思路,一点点成长。。。)
    学习python的第一个小目标:通过requests+xlrd实现简单接口测试,将测试用例维护在表格中,与脚本分开。
    队列 —— 先入先出的数据结构
    卷积神经网络的简单可视化
    HOG 特征提取算法(实践篇)
  • 原文地址:https://www.cnblogs.com/fhuafeng/p/1786170.html
Copyright © 2020-2023  润新知