2015-04-18 78 views
0

我仍然很窮,尤其是在JQuery上。 如果點擊JSTree href中的某一個,並且內容應該加載在同一頁面上,如何加載某些內容。

JSTree無法加載點擊的內容

當我從div中刪除div id「tree_1」時,它通常作爲導航菜單正常工作(不像JSTree節點)。

請幫忙。
謝謝。

$('#tree_1').jstree({ 
 
     "core" : { 
 
      "themes" : { 
 
       "responsive": false 
 
      }    
 
     }, 
 
     "check_callback" : true, 
 
     "types" : { 
 
      "default" : { 
 
       "icon" : "fa fa-folder icon-state-warning icon-lg" 
 
      }, 
 
      "file" : { 
 
       "icon" : "fa fa-file icon-state-warning icon-lg" 
 
      } 
 
     }, 
 
     "plugins": ["state"] 
 
    }); 
 

 
    $('#tree_1').on('select_node.jstree', function(e,data) { 
 
     var link = $('#' + data.selected).find('a'); 
 
     if (link.attr("href") != "#" && link.attr("href") != "javascript:;" && link.attr("href") != "") { 
 
      if (link.attr("target") == "_blank") { 
 
       link.attr("href").target = "_blank"; 
 
      } 
 
      //document.location.href = link.attr("href"); 
 
      return false; 
 
     } 
 
    });
<div id="tree_1" class="tree-demo scroller" style="height:150px"> 
 
    <ul id="klass"> 
 
    <li><a href="home">Load Home Page</a></li> 
 
    <li><a href="klassing">Load Klassing Page</a></li> 
 
    </ul> 
 
</div> 
 

 
<div id="content"></div> 
 

 
<script> 
 
$(document).ready(function(){ 
 
    $('#content').load('content/index.php'); 
 
    
 
    $('ul#klass li a').click(function(){ 
 
    var page = $(this).attr('href'); 
 
    $('#content').load('content/' + page + '.php'); 
 
    return false; 
 
    }); 
 
}); 
 
</script>

回答

0

卸下底部腳本標記,而不是你的select_node事件處理程序試試這個:

$('#tree_1').on('select_node.jstree', function(e,data) { 
     var href = data.node.a_attr.href; 
     if (href && href != "#" && href != "javascript:;") { 
      $('#content').load('content/' + href + '.php'); 
     } 
    });