【问题标题】:link not opening in new tab in JStree链接未在 JStree 的新选项卡中打开
【发布时间】:2019-10-04 14:00:05
【问题描述】:

我有这个包含文件链接的 JStree,我只想在新选项卡中打开。但即使将目标设置为 _blank 后也不会在新选项卡中打开它。

<div id="jstree" class="jstree jstree-1 jstree-default" role="tree" aria-multiselectable="true" tabindex="0"
    aria-activedescendant="j1_11" aria-busy="false">
    <ul class="jstree-container-ul jstree-children" role="group">
        <li role="treeitem" aria-selected="false" aria-level="1" aria-labelledby="j1_3_anchor" aria-expanded="true"
            id="j1_3" class="jstree-node jstree-open"><i class="jstree-icon jstree-ocl" role="presentation"></i><a
                class="jstree-anchor" href="#" tabindex="-1" id="j1_3_anchor"><i class="jstree-icon jstree-themeicon"
                    role="presentation"></i>
                Files
            </a>
            <ul role="group" class="jstree-children">
                <li role="treeitem" aria-selected="false" aria-level="2" aria-labelledby="j1_4_anchor" id="j1_4"
                    class="jstree-node  jstree-leaf"><i class="jstree-icon jstree-ocl" role="presentation"></i><a
                        class="jstree-anchor  glyphicon glyphicon-download-alt anchorTag" href="/file1" tabindex="-1"
                        target="_blank" id="j1_4_anchor"><i class="jstree-icon jstree-themeicon"
                            role="presentation"></i>
                        Slide 7.png
                    </a></li>
                <li role="treeitem" aria-selected="false" aria-level="2" aria-labelledby="j1_5_anchor" id="j1_5"
                    class="jstree-node  jstree-leaf"><i class="jstree-icon jstree-ocl" role="presentation"></i><a
                        class="jstree-anchor  glyphicon glyphicon-download-alt anchorTag" href="/file2" tabindex="-1"
                        target="_blank" id="j1_5_anchor"><i class="jstree-icon jstree-themeicon"
                            role="presentation"></i>
                        Slide 6.jpg
                    </a></li>

            </ul>
        </li>

    </ul>
</div>

【问题讨论】:

    标签: javascript html jstree


    【解决方案1】:

    你可以在点击时使用一个类来获取 href 和 target 来打开它

    $("#jstree").jstree().on("click","anchorTag" function (e, data) {
        var href = this.href;
        window.open(href, this.attr.target)
     });
    

    还有很多其他方法,但我觉得这个很简单

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-25
      • 2020-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-04
      相关资源
      最近更新 更多