【问题标题】:JQuery seems to be blocked by something elseJQuery 似乎被其他东西阻止了
【发布时间】:2014-02-03 20:50:14
【问题描述】:

JQuery 好像被屏蔽了

您好,我已经遇到这个问题好几天了,我只是找不到解决这个问题的方法,或者解决它。
我想做的很简单,我想读出一个大项目文件夹的每个子文件夹。然后将缩略图和 figcapture 分配给该文件夹。通过一个简单的 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

?>

【问题讨论】:

  • 我看不到您在哪里实际使用 id 创建元素。 edit 正如(突然删除?)评论正确指出的那样,您将其添加为一个类,而不是一个 id。因此,您可能想要使用.ID...,而不是#ID...
  • 你能打开页面并查看它的原始源吗?告诉我你的&lt;script&gt; 元素是如何呈现的!
  • 你的 setter 设置类 class="ID'.trim($projectsCaptions[$i])
  • @Arphrial 我要上传了,请等一下
  • 感谢@johnSmith,尽管这是一个错误,但它不是阻止 jquery 的那个。 denger 这是您可以查看呈现代码的站点。继续architektur,然后是unsere referenzen,在这里你可以看到我正在尝试但失败的地方......别担心,我会在最后做性能方面的工作,这只是早期的测试版

标签: javascript php jquery html for-loop


【解决方案1】:

当您需要使用 class 时,您正在通过 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 () {

【讨论】:

  • 这看起来是正确的。您的链接是使用class 属性作为其标识符生成的:class="ID'.trim($projectsCaptions[$i]).'"。 jQuery 不起作用,因为它试图将事件绑定到不存在的元素。
  • 但是还是不行……我上传到服务器上,你可以看看。请稍等
  • denger test 继续architektur,然后在referenzen,这就是魔法发生的地方@Arphrial
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-08-23
  • 1970-01-01
  • 2013-02-17
  • 2010-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多