在php代码中实现js函数

时间:2014-06-20 11:14:05

标签: javascript php toggle

我依赖的人需要一些帮助来实现php代码中的js函数。我想要实现的你可以在第一个代码中找到html one和我在php中做的同样的事情是第二个。

       

   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   <script type="text/javascript">

       function toggle_visibility(id) {
           var e = document.getElementById(id);
           if (e.style.display == 'block') e.style.display = 'none';
           else e.style.display = 'block';
       }

   </script>
   <style> 
   #foo1 {
       list-style-type: none;
       padding-bottom:10px;
       display: none;
   }
   #foo2 {
       list-style-type: none;
       padding-bottom:10px;
       display: none;
   }
   </style>
   </head>
   <body>
   <h3>Programs</h3>

   <a href="#" onclick="toggle_visibility('foo1');">Movies</a>

   <div id="foo1">
       <ul style="padding-bottom:15px;list-style-type: none;">
           <li style="padding-bottom:15px;"><a href="itms-services://?action=download-manifest&url=http://kickass.to/the-official-uk-top-40-singles-chart-15-06-2014-t9225052.html" onclick="this.color=#FF0000;"> _Movie~2014-06-16-1808-name-muzic--1.0.1-4035-g0d107d0~Host</a>

           </li>
           <li style="padding-bottom:15px;"><a href="itms-services://?action=download-manifest&url=http://kickass.to/the-official-uk-top-40-singles-chart-15-06-2014-t9225052.html" onclick="this.color=#FF0000;"> _Movie~2014-06-16-1808-name-muzic--1.0.1-4035-g0d107d0~Host</a>

           </li>
           <li style="padding-bottom:15px;"><a href="itms-services://?action=download-manifest&url=http://kickass.to/the-official-uk-top-40-singles-chart-15-06-2014-t9225052.html" onclick="this.color=#FF0000;"> _Movie~2014-06-16-1808-name-muzic--1.0.1-4035-g0d107d0~Host</a>

           </li>
       </ul>
   </div>

   <br><a href="#" onclick="toggle_visibility('foo2');">Music</a>
   <div id="foo2">
   <ul style="padding-bottom:15px;list-style-type: none;">
           <li style="padding-bottom:15px;"><a href="itms-services://?action=download-manifest&url=https://kickass.to/game-of-thrones-s04e10-720p-hdtv-x264-killers-rartv-t9225859.html" onclick="this.color=#FF0000;"> _Muzic~2014-06-16-1808-name-muzic--1.0.1-4035-g0d107d0~Host</a>

           </li>
           <li style="padding-bottom:15px;"><a href="itms-services://?action=download-manifest&url=http://kickass.to/game-of-thrones-s04e10-720p-hdtv-x264-killers-rartv-t9225859.html" onclick="this.color=#FF0000;"> _Muzic~2014-06-16-1808-name-muzic--1.0.1-4035-g0d107d0~Host</a>

           </li>
           <li style="padding-bottom:15px;"><a href="itms-services://?action=download-manifest&url=http://kickass.to/game-of-thrones-s04e10-720p-hdtv-x264-killers-rartv-t9225859.html" onclick="this.color=#FF0000;"> _Muzic~2014-06-16-1808-name-muzic--1.0.1-4035-g0d107d0~Host</a>
                </li>
       </ul>
   </div>


   </body></html>

所以我想要实现的是这个,我有一个文件夹,让我们说Folder1,在这个文件夹中我有3个子文件夹让我们说Subfolder1,Subfolder2和Subfolder3以及这3个子文件夹中的每一个我有5个文件需要下载。我想为下载链接创建3个切换链接。所以我将有3个切换链接,称为Subfolder1,Subfolder2和Subfolder3。当您使用js函数单击它们时,您可以更改每个文件夹链接的子文件夹的显示属性。因此,如果单击Subfolder1,它将展开并显示5个文档的下载链接。 并且Subfolder1中的一个文件的名称是testDownload1.exe,因此该链接将具有与将要下载的文件的名称连接的父文件夹的名称。所以名称将是:Subfolder1_testDownloaded

<?
    if (isset($_POST['password']))
    {
        $password = $_POST['password'];
        $goodPass = '******';
        if ($password == $goodPass)
            $_SESSION['loggedIn']=1;
        }
        if (!isset($_SESSION['loggedIn'])) 
            showPasswordForm();
        else
        {
           $install_links = getDirectory(".");
           rsort($install_links);
           $oldPrefix = "";
           foreach ($install_links as $key => $val) 
           {
               $strip_val = strip_tags($val);

               $prefix = explode("~",$strip_val);
               //echo "Prefix:|".$prefix[0]."|</br>";
               if (strcmp($prefix[0],$oldPrefix)!=0)
                  echo <<<EOT </div> <a href='#'            onclick="toggle_visibility('".$prefix[0]."');"> "".$prefix[0].""</a><div id="".$prefix[0]."">EOT;
                  $oldPrefix = $prefix[0];
                  echo '<li style="padding-bottom:15px">'.$val.'</li><br/>';
            }
        }

   function getDirectory( $path = '.', $level = 0 ){ 

       $echoData = false;

       $protocol = isset($_SERVER['HTTPS']) ? "https://" : "http://";
       $root_folder_url_prefix = $protocol.".....";

       $ignore = array( 'cgi-bin', '.', '..','WHat.app.dSYM' ); 
       // Directories to ignore when listing output. Many hosts 
       // will deny PHP access to the cgi-bin. 

       $dh = @opendir( $path ); 
       // Open the directory to the handle $dh 

       $install_links = array();

       while( false !== ( $file = readdir( $dh ) ) ){ 
       // Loop through the directory 

           if( !in_array( $file, $ignore ) ){ 
           // Check that this file is not to be ignored 

               $spaces = str_repeat( '&nbsp;', ( $level * 4 ) ); 
               // Just to add spacing to the list, to better 
               // show the directory tree. 

               if( is_dir( "$path/$file" ) ){ 
               // Its a directory, so we need to keep reading down... 

                   if ( $echoData) 
                      echo "<strong>$spaces $file</strong><br />"; 
                      $subarray = getDirectory( "$path/$file", ($level+1) ); 

                      $install_links = array_merge($install_links, $subarray);
                      // Re-call this same function but on a new directory. 
                      // this is what makes function recursive. 

               } else { 
                   if (strstr($file,".ipa"))
                   {
                       //echo ">>".$file."<<";
                       $filename = str_replace(".ipa","",$file);
                       $plist_path = substr($path,2);
                       $plist_path = str_replace("/","~",$plist_path);
                       $plist_location =            $root_folder_url_prefix.$plist_path."~".$filename.".plist";
                       $link = '<a href="itms-services://?action=download-manifest&url='.$plist_location.'"  onclick="this.color=#FF0000;"> '.$plist_path.'-'.$filename.'</a>';

                       if ( $echoData) 
                           echo "$spaces $link<br/>";

                       array_push($install_links,$link);

                   }
                   else             
                   {
                       //   echo "$spaces $file<br />"; 
                       // Just print out the filename 
                   }
               } 

           } 

       } 

       closedir( $dh ); 
       // Close the directory handle 

       return $install_links;
   }




   function showPasswordForm()
   {
?>
   <center>
   <form action="index.php" method="post">
   <table>
   <tr><td>User:</td>  <td> <input type="text" name="user" /></td></tr>
   <tr><td>Password:</td> <td> <input type="password" name="password" /></td></tr>
   <tr><td colspan="2" align="center"><input type="submit" value="Submit" /></td>           </tr>
   </table>
   </form> 
   </center>
<?
   }

?>

0 个答案:

没有答案