当前位置: 首页>>代码示例>>C#>>正文


C# Element.SetAttribute方法代码示例

本文整理汇总了C#中System.Html.Element.SetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Element.SetAttribute方法的具体用法?C# Element.SetAttribute怎么用?C# Element.SetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Html.Element的用法示例。


在下文中一共展示了Element.SetAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Initialize

        /// <summary>
        /// Initializes a behavior by attaching it to the specified element.
        /// When overriding this, be sure to call the base functionality before the implementation
        /// in the derived class.
        /// </summary>
        /// <param name="element">The element to attach the behavior to.</param>
        /// <param name="options">Any initialization options that the behavior should consume.</param>
        public virtual void Initialize(Element element, Dictionary<string, object> options)
        {
            Debug.Assert(_element == null, "A behavior should be initialized only once.");
            Debug.Assert(element != null, "Expected a valid element to initialize a behavior.");

            _element = element;

            // Automatically expose the behavior on the DOM element as an expando using
            // the name of the behavior as the key.

            string name = (string)Type.GetField(this.GetType(), BehaviorNameKey);
            Type.SetField(element, name, this);

            // Add a 'behaviors' expando on the element which is a key/value pair
            // list of behavior name -> behavior instance mapping.

            Dictionary<string, Behavior> behaviors = (Dictionary<string, Behavior>)Type.GetField(element, BehaviorsKey);
            if (behaviors == null) {
                behaviors = new Dictionary<string, Behavior>();
                Type.SetField(element, BehaviorsKey, behaviors);
            }

            behaviors[name] = this;

            // Set data-behavior on the element if it is not already set (i.e. if the behavior
            // is being programmatically constructed), so that if DisposeBehaviors is called,
            // then this element is picked up via the CSS query used to find elements that have
            // behaviors.
            // TODO: Fix Script.Web
            if ((bool)Type.InvokeMethod(element, "hasAttribute", BehaviorsAttribute) == false) {
                element.SetAttribute(BehaviorsAttribute, String.Empty);
            }
        }
开发者ID:noodlefrenzy,项目名称:scriptsharp,代码行数:40,代码来源:Behavior.cs


注:本文中的System.Html.Element.SetAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。