0

我用 jQuery.jsTree 建立了一个菜单,每个项目都应该包含一个指向特定页面的链接。由于阻止了 jsTree 的标准行为,因此无法单击这些链接

<a href="index.php?content=example" ... >....</a> 

链接(这实际上是我的链接之一。index.php 是我的标准页面,只是内容将被替换)。为了解决这个问题,我找到了这个解决方案:

jQuery(".tree").bind("select_node.jstree", function (e, data) {
    document.location = data.rslt.obj.children("a").attr("href");
});

该解决方案部分适用于我,这意味着单击的链接有效,但在打开的窗口中 Firebug 告诉我未定义 jQuery。浏览器是否有可能在 document.location 上“忘记”库导入(正如我所提到的,我留在 index.php 页面上并只是替换内容)?

另一个问题是:有没有人知道在不编辑库本身的情况下启用 jsTree 中的链接的更好解决方案?

提前致谢!

4

1 回答 1

1

如果您的链接最初看起来像:

<a href="index.php?content=example" ... >....</a> 

并且您想将内容加载到具有 ID 的 div 中maincontent

您可以执行以下操作:

$(".tree a").each(function(){
  var $this = $(this);
  $this.click(function(){
     $("#maincontent").load($this.href, function(){
        // this callback functions fires once load is complete,
        // incase you need to do post-load operations
     });
     return false;
  });
});

这将绕过像普通链接那样加载新页面,并通过 AJAX 获取页面并将返回的 HTML 加载到DIVwith IDmaincontent中。

代码未经测试,但我过去做过,所以应该按原样工作。

于 2013-10-02T13:27:34.840 回答