代码之家  ›  专栏  ›  技术社区  ›  ebillis

轴图标不可单击

  •  0
  • ebillis  · 技术社区  · 6 年前

    我有一个 枢轴元件 在我的页面上,这是可行的,但是当我想通过图标来改变文本时,它们变得不可点击,我们必须点击灰色部分。你知道怎么让它们可以点击吗?

    enter image description here

    部分代码:

    <li id="listPivotAccount" class="ms-Pivot-link is-selected " data-content="account" title="Mon compte" tabindex="1">
       <i style="" class=" ms-Icon ms-Icon--Accounts" aria-hidden="true"></i>
    </li>
    

    You can check the code here

    3 回复  |  直到 6 年前
        1
  •  2
  •   Gary Thomas    6 年前

    作为记录,我从未使用过SharePoint,因此可能有一个更优雅的解决方案。

    可以通过在当前JavaScript之后添加此普通JavaScript来修复此行为:

        // select all icons
        var msIcons = document.querySelectorAll(".ms-Icon");
    
        // loop all icons
        for (var i = 0; i < msIcons.length; i++) {
    
            // add a click event to the nearest element with class "ms-Pivot-link"
            msIcons[i].closest(".ms-Pivot-link").addEventListener("click", function() {
                this.click();
            });
        }
    

    上面代码的jQuery示例:

        $(".ms-Icon").on("click", function() {
            $(this).closest(".ms-Pivot-link").click();
        });
    
        2
  •  2
  •   Alexandr Tovmach    6 年前
    var Dropdown = new Class({
        initialize: function() {
            var e = this;
            document.addEvents({
                "click:relay(.windowLabel, .dropdown a.dropdownTrigger)": function(t, n) {
                    t && (t.preventDefault(),
                    t.stopPropagation()), // issue is here
                    e.showPopover.call(e, n)
                }
            }),
            document.body.addEventListener("click", function(t) {
                e.hideOutside.call(e, t)
            })
        },
        // ...
    })
    

    防止事件传播 ,因此所有嵌套元素都不应发出所需的内容。


    您可以尝试以不同的方式添加图标(例如使用 :before , :after

        3
  •  0
  •   ebillis    6 年前

    修复它的简单方法是通过单击触发轴心。因此,如果使用JQuery:

    $('.ms-Icon').click(function () {
                var pivot = $(this).closest(".ms-Pivot-link");
                pivot.click();
            });
    

    短而兼容IE>9