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


C# Element.appendChild方法代码示例

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


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

示例1: renderValue

        /// <summary>
        /// Renders a single value that can be selected by the user.
        /// </summary>
        /// <param name="label">Text representing the value to the user.</param>
        /// <param name="value">The value that will be applied to the setting if chosen by the user.</param>
        /// <param name="parent">DOM element that should be the parent of the value's DOM fragment.</param>
        protected void renderValue(string label, object value, Element parent)
        {
            // Creates a SPAN element
            var span = (HTMLSpanElement)window.document.createElement("SPAN");
            span.innerHTML = label;

            // As with the menu, handling the mousedown event prevents focus changes caused by the click event on some browsers
            span.addEventListener("mousedown", (e) =>
            {
                e.preventDefault();
                e.stopPropagation();

                // do nothing if this is already the selected value
                if (this.value == value) return;

                // select the new value
                this.value = value;
                select(value);

                // notify the menu and other settings of the selection
                triggerChanged(key, value);
            }, false);

            span["value"] = value;
            spans.push(span);
            parent.appendChild(span);
        }
开发者ID:Ventajou,项目名称:BladeGame,代码行数:33,代码来源:SingleChoiceSetting.cs

示例2: render

 /// <summary>
 /// Renders the setting control's markup
 /// </summary>
 /// <param name="parent">The parent DOM element</param>
 public void render(Element parent)
 {
     _container = (HTMLElement)window.document.createElement("DIV");
     var h2 = (HTMLElement)window.document.createElement("H2");
     h2.innerHTML = name;
     _container.appendChild(h2);
     renderContent(_container);
     parent.appendChild(_container);
 }
开发者ID:Ventajou,项目名称:BladeGame,代码行数:13,代码来源:Setting.cs

示例3: Render

        /// <summary>
        /// Renders the menu and its settings.
        /// </summary>
        /// <param name="parent"></param>
        public void Render(Element parent)
        {
            // The menu's button in the toolbar and also the root element.
            var menu = (HTMLAnchorElement)window.document.createElement("A");
            menu.href = "#";
            menu.className = "menu " + _className;

            // The menu popup element
            _popup = (HTMLAnchorElement)window.document.createElement("A");
            _popup.href = "#";
            _popup.className = "popup";

            // Shows the menu name as a title
            var title = (HTMLDivElement)window.document.createElement("H1");
            title.innerHTML = _name;
            _popup.appendChild(title);

            if ((dynamic)_settings && (dynamic)_settings.length)
            {
                // Renders all of the menu settings
                foreach (var setting in _settings)
                {
                    // Attach the changed event to the settings controls
                    setting.changed += settingChanged;
                    setting.render(_popup);
                }

                _popup.appendChild(window.document.createElement("BR"));

                // Button to apply the setting changes.
                var applyButton = (HTMLAnchorElement)window.document.createElement("A");
                applyButton.innerHTML = "Apply";
                applyButton.className = "button ok";
                _popup.appendChild(applyButton);
                // Handling the mousedown event to ensure the click is captured on all browsers.
                applyButton.addEventListener("mousedown", (e) =>
                    {
                        // Deselect menu to hide it
                        menu.className = menu.className.replace(" selected", "");
                        // Save the changes.
                        persistSettings();
                    }, false);

                // Button to exit the menu and discard changes
                var cancelButton = (HTMLAnchorElement)window.document.createElement("A");
                cancelButton.innerHTML = "Cancel";
                cancelButton.className = "button cancel";
                _popup.appendChild(cancelButton);
                // Handling the mousedown event to ensure the click is captured on all browsers.
                cancelButton.addEventListener("mousedown", (e) =>
                    {
                        menu.className = menu.className.replace(" selected", "");
                    }, false);
            }
            else
            {
                // Just in case a developer creates a menu with no settings
                _popup.appendChild(window.document.createTextNode("No settings available."));
            }

            // Prevents the # from being appended to the URL
            menu.addEventListener("click", (e) => { e.preventDefault(); }, false);

            // Certain browsers will trigger the blur event unless we capture and dispose of the mousedown event
            menu.addEventListener("mousedown", (e) =>
                {
                    // Make sure nothing catches the event as this could close the menu.
                    e.preventDefault();

                    // If the mouse event target occured inside the menu, then
                    if (contains(menu, (Element)e.target)) return;

                    // Check if the menu is open or closed
                    if (menu.className.indexOf("selected") < 0)
                    {
                        // If closed, set the setting controls from the game settings object
                        loadSettings();

                        // Showing the menu by setting the 'selected' CSS class
                        menu.className += " selected";
                    }
                    else
                    {
                        // Hiding the menu by removing the 'selected' CSS class
                        menu.className = menu.className.replace(" selected", "");
                    }

                    // Set the focus because when the popup is blurred, ir needs to close.
                    _popup.focus();
                }, false);

            // Catching the popup's blur event, this lets us close the popup no matter what gets clicked
            _popup.addEventListener("blur", (e) =>
                {
                    menu.className = menu.className.replace(" selected", "");
                    e.preventDefault();
//.........这里部分代码省略.........
开发者ID:Ventajou,项目名称:BladeGame,代码行数:101,代码来源:Menu.cs


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