繁体   English   中英

如何在dynaTree jQuery插件中点击超链接?

[英]How to make hyperlinks in dynaTree jQuery plugin clickable?

我目前正在使用dynaTree jQuery插件来渲染树。

<div id="tree" style="height:100px;">

<ul class="expanded">

    <li class="expanded" id="shtml_1" >
        <a class="ajaxify" href="jsTree.html" >Root node 1</a>
        <ul>
            <li id="shtml_2">
                <a href="#">Child node 1</a>
                <ul>
                <li id="a"><a href="#">Child node 1-1</a></li>
                <li id="x"><a href="b">Child node 1-2</a></li>
                </ul>
            </li>               
            <li id="c"><a href="#">Child node 2</a></li>
        </ul>
    </li>
    <li id="shtml_4">
        <a href="#">Root node 2</a>
    </li>
</ul>

Javascript -

  $('.ajaxify').ajaxify({
  target: '#container'
  });

    $(function(){
    $("#tree").dynatree({
      title: "Sample Theming",
      // Image folder used for data.icon attribute.
      imagePath: "skin-custom/",
      onSelect: function(node) {
        alert ("You selected " + node);
      }
    });
  });

现在我想

  • 使用jQuery Ajaxify插件(http://max.jsrhost.com/ajaxify/demo.php),这样当用户点击任何节点时,就会调用ajax调用并将结果加载到div中。

要么

  • 使用jquery绑定锚标记,以便我可以使用onclick ajax请求。

现在每当我使用dynaTree时它会覆盖默认行为并阻止锚标记被点击。 有关如何做到这一点的任何想法?

Dynatree默认会删除<a>标签,因此实现onActivate处理程序可能更容易:

onActivate: function(node) { 
    if( node.data.href ){
        // use href and target attributes:
        window.location.href = node.data.href; 
//      window.open(node.data.href, node.data.target);
//      $("#div").load(node.data.href);
    }
}

从1.1.2版开始,Dynatree将直接使用<a>标签中的hreftarget属性:

<li id="x"><a href="b">Child node 1-2</a></li>

在旧版本中,您必须像这样设置href:

<li id="x" data="href: 'b'"><a href="b">Child node 1-2</a></li>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM