2011-09-01 52 views
2

我正在使用jquery列表目录,我想填充删除它中的复选框,并删除树上每个目录提交buton。怎么做? 我在下面使用此代码。jquery目录树

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
<title>jQuery Drop Down Menu</title> 

<!-- CSS For The Menu --> 
<link rel="stylesheet" href="stylee.css" /> 

</head> 
<body> 

<!-- Menu Start --> 
<div id="jQ-menu"> 

<?php 
error_reporting(0); 
    $path = "store/".$diro."/"; 

    function createDir($path = '.') 
    { 
     if ($handle = opendir($path)) 
     { 
      echo "<ul>"; 

      while (false !== ($file = readdir($handle))) 
      { 
       if (is_dir($path.$file) && $file != '.' && $file !='..') 
        printSubDir($file, $path, $queue); 
       else if ($file != '.' && $file !='..') 
        $queue[] = $file; 
      } 

      printQueue($queue, $path); 
      echo "</ul>"; 
     } 
    } 

    function printQueue($queue, $path) 
    { 
     foreach ($queue as $file) 
     { 
      printFile($file, $path); 
     } 
    } 

    function printFile($file, $path) 
    { 
     echo "<li><a href=\"".$path.$file."\">$file</a></li>"; 
    } 

    function printSubDir($dir, $path) 
    { 
     echo "<li><span class=\"toggle\">$dir</span>"; 
     createDir($path.$dir."/"); 
     echo "</li>"; 
    } 

    createDir($path); 
?> 

</div> 
<!-- End Menu --> 


<!-- Add jQuery From the Google AJAX Libraries --> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> 


<!-- jQuery Color Plugin --> 
<script type="text/javascript" src="jquery.color.js"></script> 

<!-- Import The jQuery Script --> 
<script type="text/javascript" src="jMenu.js"></script> 

</body> 
</html> 
+0

能否请您提供一个链接到一个例子,我们可以看到在行动这棵树菜单? – thwd

回答

0

什么是你想让用户能够对树做什么,它应该如何反应?在预感中,我发现至少有两种方法可以去。您可以立即输出复选框和按钮的html,然后使用选择器向他们添加行为,或者您可以先输出树,然后在document.ready之后使用jquery的DOM修改(如before())修改dom。

根据你想要的功能,它可能是这样的:

function printFile($file, $path) 
{ 
    echo "<li class='fileNode'><a href=\"".$path.$file."\">$file</a></li>"; 
} 
function printSubDir($dir, $path) 
{ 
    echo "<li class='dirNode'><span class=\"toggle\">$dir</span>"; 
    createDir($path.$dir."/"); 
    echo "</li>"; 
} 

然后在您的JavaScript这样做

$(document).ready(function 
{ 
    // you should still assign some behaviour probably 
    $(".fileNode").prepend("<input type='checkbox' />"); 
}); 

或者您也可以确保该复选框已经目前,你可以绑定一些Ajax函数到复选框'change()。 http://api.jquery.com/change/

+0

好的,我希望该用户可以从他的目录树中删除该用户的uniq文件...我不再使用这个代码...我使用这个代码从这个网站http://代码.google.com/p/editable-jquery-tree-with-php-codes/becos它是allredy在目录树上的删除功能,但是这是代码的问题...看看我的问题使用定义函数的问题...首先从网站http://code.google.com/p/editable-jquery-tree-with-php-codes/查看目录树,然后查看我的问题...如果可以的话帮助请联系我... – Blue