Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在使用jstree ui时,如何让jstree中的叶节点在单击时打开其超链接?_Javascript_Html_Jstree - Fatal编程技术网

Javascript 在使用jstree ui时,如何让jstree中的叶节点在单击时打开其超链接?

Javascript 在使用jstree ui时,如何让jstree中的叶节点在单击时打开其超链接?,javascript,html,jstree,Javascript,Html,Jstree,我使用jtree显示一个层次结构,数据如下 <div id="songchanges"><ul> <li id="phtml_1"> <a href="#">C:</a> <ul> <li id="phtml_2"> <a href="#">Music</a> <ul> <li id="phtml_3"> <a href="#">Z</a>

我使用jtree显示一个层次结构,数据如下

<div id="songchanges"><ul>
<li id="phtml_1">
<a href="#">C:</a>
<ul>
<li id="phtml_2">
<a href="#">Music</a>
<ul>
<li id="phtml_3">
<a href="#">Z</a>
<ul>
<li id="phtml_4">
<a href="#">Hans Zimmer</a>
<ul>
<li id="phtml_5"><a href="FixSongsReport_00107_2013-09-04-11-11-55_body_blqxgT7E7YOmnBbjFXQGUg==.html">C:\Music\Z\Hans Zimmer\Hannibal</a></li>
</ul>
</li>
<li id="phtml_6">
<a href="#">The Zombies</a>
<ul>
<li id="phtml_7"><a href="FixSongsReport_00107_2013-09-04-11-11-55_body_er7mjWKbAaYaf8DygP84Fg==.html">C:\Music\Z\The Zombies\Best of The Zombies</a></li>
<li id="phtml_8"><a href="FixSongsReport_00107_2013-09-04-11-11-55_body_56XgVDhsjEKWXFd4OzVldA==.html">C:\Music\Z\The Zombies\The Zombies featuring Colin Blunstone & Rod Argent</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" href="songkong.css">
<base target="main">
<script type="text/javascript" src="http://static.jstree.com/v.1.0pre/jquery.js"></script>
<script type="text/javascript" src="http://static.jstree.com/v.1.0pre/jquery.cookie.js"></script>
<script type="text/javascript" src="http://static.jstree.com/v.1.0pre/jquery.hotkeys.js"></script>
<script type="text/javascript" src="http://static.jstree.com/v.1.0pre/jquery.jstree.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script type="text/javascript" class="source below">
$(function () {
$("#songchanges")
.jstree({
"plugins" : ["themes","html_data","ui","crrm","hotkeys"],
"core" : { "initially_open" : [ "phtml_1" ] }
})
.bind("loaded.jstree", function (event, data) {
});
$("#songchanges").bind("open_node.jstree", function (e, data) {
data.inst.select_node("#phtml_1", true);
});
});
</script></head>
并尝试了它,但.delegate选项没有效果,我想我必须删除“ui”插件,但我的页面看起来好像我从来没有应用过jstree

bind选项有点起作用了,因为每次单击任何节点时,它都会显示一个恼人的警报窗口,显示id。那么,我如何将其改为在右手边打开链接呢

更新 找到了这个答案

添加

  .bind("select_node.jstree", function (e, data) {
    var href = data.rslt.obj.children("a").attr("href");
    // this will load content into a div:
    $("#contents").load(href);
    // this will follow the link:
    document.location.href = href;
  }) 
现在,当点击时,链接被打开,不幸的是,它用页面替换了左侧框架,而我想把它放在右侧窗格中,任何想法

试试这个

$("#demo2").jstree().bind("select_node.jstree", function (e, data) { 
        var href = data.rslt.obj.children("a").attr("href"); 
        document.location.href = href; 

      //  $("#the_div").load(href); 
    }) ;
对于新版本

$("#demo2").jstree().bind("select_node.jstree", function (e, data) {
     var href = data.node.a_attr.href;
     document.location.href = href;
});

我知道这篇文章有点老了,但我是如何做到这一点的:

html:

<div id="entryPointTree">
    <ul>
        <li>Produits des mains
           <ul>
              <li><a href="http://www.google.ca" class="jstree-clicked">Lien 1</a></li>
              <li>item 2</li>
           </ul>
        </li>
        <li>Produits des pieds</li>
    </ul>
</div>

其他答案都不是我想要的:节点标题中有多个
标记。这就是我的工作原理:

HTML

<div id="object-tree">
  <ul>
     <li>SomeTitle <a href="/link1" target="_blank">link1><a href="/link2" target="_blank">link2</a></li>
  </ul>
</div>

我的v3.3.4解决方案运行良好

tree.jstree().on("click", ".jstree-anchor", function() {
    document.location.href = this.href;
});

我重新表述了我的问题并在这里得到了答案,我需要将第二行改为:var href=data.node.a_attr.href;更新版本(3+)data.rslt不再可用。data.node返回我刚刚测试过的node object,它仍然可以正常工作,与我能找到的所有其他过时建议相反。请注意:您的示例中的第2行不需要单击行为才能工作。最好使用
窗口。打开(data.node.a_attr.href,data.node.a_attr.target)
而不是这两行,因为它还可以正确处理(可选)
目标
声明。如果(href[0]!=“#”)声明,我必须添加

<div id="object-tree">
  <ul>
     <li>SomeTitle <a href="/link1" target="_blank">link1><a href="/link2" target="_blank">link2</a></li>
  </ul>
</div>
jQuery('#object-tree').jstree().bind("select_node.jstree", function (e, data) {
  // Allow links to work from within jstree nodes
  window.open( jQuery(data.event.originalEvent.originalTarget).attr('href'), '_blank');
});
tree.jstree().on("click", ".jstree-anchor", function() {
    document.location.href = this.href;
});