gpt4 book ai didi

javascript - 在使用 jstree ui 时,如何让 jstree 中的叶节点在单击时打开它们的超链接?

转载 作者:太空狗 更新时间:2023-10-29 13:33:49 25 4
gpt4 key购买 nike

我用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>

它显示正常,作为一个文件系统。

这是框架集的一部分,显示在屏幕的左侧,当用户单击叶节点时,我希望它打开右侧的附加链接(就像在我对其应用 jtree 东西之前所做的那样) )

我的jtree配置如下

<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>

我读了demo3例子

$(function () {
$("#demo3")
.jstree({ "plugins" : ["themes","html_data","ui"] })
// 1) if using the UI plugin bind to select_node
.bind("select_node.jstree", function (event, data) {
// `data.rslt.obj` is the jquery extended node that was clicked
alert(data.rslt.obj.attr("id"));
})
// 2) if not using the UI plugin - the Anchor tags work as expected
// so if the anchor has a HREF attirbute - the page will be changed
// you can actually prevent the default, etc (normal jquery usage)
.delegate("a", "click", function (event, data) { event.preventDefault(); })
});

并尝试了它,但 .delegate 选项没有效果,我想我必须删除“ui”插件,但尝试我的页面看起来就像我从未应用过 jstree。

绑定(bind)选项有点管用,因为它会显示一个烦人的警告窗口,每次我单击任何节点时都会显示 id。那么我该如何更改它以改为在右侧打开链接呢?

更新找到这个答案 Jstree nodes don't work when ui plugin is used

添加

  .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;
})

现在单击时会打开链接,不幸的是它用页面替换了左侧框架,而我希望它把它放在右侧 Pane 中,任何想法。

最佳答案

对于新版本;

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

关于javascript - 在使用 jstree ui 时,如何让 jstree 中的叶节点在单击时打开它们的超链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18611317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com