本文整理汇总了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);
}
}