[英]Is my jQuery .load bloacked by the CMS?
我在Movable Type 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>
當我加載頁面時,會顯示縮略圖,但是當我單擊它們時,會加載pathtoimage.jpg而不是prettyphoto。
我的問題:我是在做錯什么還是出於安全原因而移動類型阻塞了執行? 如何調試呢? 我有螢火蟲,但不知道要尋找什么。
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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.