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