JQuery似乎被其他东西阻止了

时间:2014-01-15 11:43:20

标签: javascript php jquery html5 for-loop

JQuery似乎被阻止了

你好,我已经面对这个问题已经好几天了,我找不到办法解决这个问题,或者围绕它解决这个问题。
我想要做的很简单,我想读出一个大项目文件夹的每个子文件夹。然后将缩略图图像和图像分配到此文件夹。通过一个简单的for循环,php为我构建了这个。一切都很完美和快速。唯一的问题是jquery不会响应。
即使我用这种技术创造了各种菜单。正如您在我的代码中看到的那样,在“脚本”标签中,我有jquery代码似乎不起作用。
我不知道php放在某个地方的某个空间,或者我只是看了太长时间看这个代码来查看错误。

我感谢任何帮助。

<?php 


/*Because of the "ease of use" aspect of this site, I prefered to write it completely in PHP,
advantage of that: 
Images are loaded directly out of the folder, so I can just drag and drop something onto the server without having to write aditional code.
As you see, it can save a lot of time.*/


echo "<h1>Referenzen</h1><br>";

$projects = scandir('../src/sub/credentials');      //The credentials directory is being scanned and converted into an array.
    $projectsSize = count($projects);                       //$size is being created. It counts the number of objects in the array which has been created above.


$projectsCaptions = file('../src/sub/captionsOfCredentials.txt'); //Edit the name of the figcaption in the "captionsOfCredentials.txt".


for($i = 2; $i < $projectsSize; $i++){      /*Simple "for" loop, that creates $i with the size of two, because PHP is 0-index based and has the "dot" and the "dotdot" folder. The loop stops at the end of the array($size).*/
    echo    '<a href="index.php#PRJ'.trim($projectsCaptions[$i]).'" class="ID'.trim($projectsCaptions[$i]).'">
                <div class="projectFolder">
                    <img src="src/sub/credentialsThumb/project_00'.$i.'.jpg" width="100%" />
                        <figcaption>'
                            .$projectsCaptions[$i].
                        '</figcaption>
                </div>
            </a>'; 

        /*Project folder level starts here.*/
    $images = scandir('../src/sub/credentials/project_00'.$i);
        $imagesSize = count($images);

    for($k = 3; $k < $imagesSize; $k++){
        $tempID = ('ID'.trim($projectsCaptions[$i]).'.php');    //$tempID is the entire file name including the .php part.



            $handle = fopen($tempID, "a") or die ('Unable to open '.$tempID.' , please contact admin A.S.A.P..');
                $imagesCode = 'test';
                    fwrite($handle, $imagesCode);



    }
    //end second for-loop
                echo "
        <script>
        $(document).ready(function () {
            $('#ID".$projectsCaptions[$i]."').click(function () {
                $('#mainContent').load('de-DE/".$tempID."');
            });
        });
        </script>";
}
//end first for-loop

?>

1 个答案:

答案 0 :(得分:1)

当您需要使用时,您将通过 id 选择元素。将JS块更改为:

$(document).ready(function () {
    // Note ".ID" not "#ID"  
    $('.ID".$projectsCaptions[$i]."').click(function () {
        $('#mainContent').load('de-DE/".$tempID."');
    });
});

<强>更新

好像你在$projectsCaptions[$i]中也有一个非法角色。它很可能是换行符。尝试在trim()

中包含上面的参考文献
$('.ID" . trim($projectsCaptions[$i]) . "').click(function () {