我的jQuery .load是否被CMS搞砸了

Is my jQuery .load bloacked by the CMS?

本文关键字:CMS jQuery load 是否 我的      更新时间:2023-09-26

我在可移动类型CMS页面中使用了prettyPhoto。要使其工作,我必须使用

<p>
    <mt:setvarblock name="html_head" append="1">
        JS scripts here
    </mt:include>
</p>

部分。要制作一个包含 30-40 张图片的画廊,我必须为每张图片添加一个看起来像这样的块:

<a href="pathtoimage.jpg" rel="prettyPhoto[GalleryName]" title="Some title">
    <img src="pathtothumbnail.jpg" alt="alt text" height="120" width="120" />
</a>

我想使用(python)脚本从csv文件生成这些条目,并将其放入Web服务器上的单独文件中。然后我使用此代码将这些条目加载到页面中:

<div id="divTestArea1"></div>
<script type="text/javascript">
    $(function() {
        $("#divTestArea1").load("output_en.txt");
    });
</script>

当我加载页面时,缩略图会显示,但是当我单击它们时,将加载路径图像.jpg而不是漂亮的照片。

我的问题:我做错了什么还是出于安全原因,可移动字体阻止了执行?如何调试?我有萤火虫,但不知道要寻找什么。

PS:将条目直接粘贴到页面中时,它会按预期工作。

编辑:完整的工作代码

<p>
    <mt:setvarblock name="html_head" append="1">
        <script src="../gallery/js/jquery-1.6.1.min.js" type="text/javascript"></script>
        <link rel="stylesheet" href="../gallery/css/prettyPhoto.css" type="text/css" media="screen" charset="utf-8" />
        <script src="../gallery/js/jquery.prettyPhoto.js" type="text/javascript" charset="utf-8"></script>
    </mt:setvarblock> 
    <mt:include name="include/header.tmpl"> 
        <div id="divTestArea1"></div>
        <script type="text/javascript">
            $(function() {
                <!--$("#divTestArea1").load("../gallery/output_en.txt");-->
                $("#divTestArea1").load("../gallery/output_en.txt", function() {
                    $("a[rel^='prettyPhoto']").prettyPhoto();
                });
            });
        </script>
        <script type="text/javascript" charset="utf-8">// <![CDATA[
            $(document).ready(function(){
                $("a[rel^='prettyPhoto']").prettyPhoto({social_tools: false});
            });
        // ]]></script>
    </mt:include>
</p>

尝试在 AJAX 完成加载后包含 prettyPhoto() 调用,因为目前插件正在页面加载时执行,在它所针对的元素在 DOM 中可用之前

 <script type="text/javascript">
   $(function() {
     $("#divTestArea1").load("../gallery/output_en.txt", function() {
         $("a[rel^='prettyPhoto']").prettyPhoto();
     });
   });
</script>