JQuery DynaTree插件 - 如何调用超链接

时间:2010-08-02 09:42:55

标签: jquery plugins dynatree jquery-dynatree

我在网页上有一个链接

<li data="url: 'www.mypage.com?index.php?CId=2&MId=14&MTId=1'">mylink

在我的js脚本中 我有

$(document).ready(function() {

 $("#tree").dynatree({
 persist: true,

 onPostInit: function(isReloading, isError) {
        this.reactivate();
 },

 onActivate: function(dtnode) {
        var isInitializing = dtnode.tree.isInitializing(); 
        var isReloading = dtnode.tree.isReloading(); 
        var isUserEvent = dtnode.tree.isUserEvent(); 

       if( dtnode.data.url )
          window.open(dtnode.data.url); 

}   

    });

});

我该怎么办而不是window.open所以url会在同一个窗口重新加载,而不是打开一个新窗口? 在我可以使用iFrame方式的网页中没有名称。

4 个答案:

答案 0 :(得分:3)

我建议

onActivate: function(node) { 
    if( node.data.href ){
        // use href to change the current frame:
        window.location.href = node.data.href; 
        // or load data into a div tag:
//      $("#div").load(node.data.href);
        // or open href in another target frame:
//      window.open(node.data.href, node.data.target);
    }
}

另见示例:How to make hyperlinks in dynaTree jQuery plugin clickable?

答案 1 :(得分:2)

dynatree现在允许您将锚标记放在li元素中。所以你可以这样做:

<li><a href="www.mypage.com\index.php?CId=2&MId=14&MTId=1" target="_top">mylink</a>

查看navigation examples here

答案 2 :(得分:0)

你试过这个解决方案吗?

$(document).ready(function() {

   $("#tree").dynatree({ persist: true,

      onPostInit: function(isReloading, isError) { this.reactivate(); },

      onActivate: function(dtnode) { 
         var isInitializing = dtnode.tree.isInitializing(); 
         var isReloading = dtnode.tree.isReloading(); 
         var isUserEvent = dtnode.tree.isUserEvent();

         if( dtnode.data.url )
            window.location.href = dtnode.data.url; 
      }
   });
});

答案 3 :(得分:0)

这是记录在案的方式:

onActivate: function(node) {
   if( node.data.href ) {
      window.open(node.data.href, node.data.target);
      return false;
   }
},