link 无法在 JStree 的新标签页中打开

link not opening in new tab in JStree

我有这个 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>

您可以在点击时使用 class 获取 href 和目标以打开它

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

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