2012-04-05 19 views
0

我的文件:如何使用jquery的.html()進行的fancybox內容

<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.fancybox-1.3.4.pack.js"></script> 

<link rel="stylesheet" href="{{ STATIC_URL }}css/jquery.fancybox-1.3.4.css" type="text/css" media="screen" /> 

{% include "submission-form.html" with section="photos" %} 
<div class="commentables"> 
    {% load thumbnail %} 

    {% for story in objects %} 
     <div class="image {% if forloop.counter|add:"-1"|divisibleby:picsinrow %}left{% else %}{% if forloop.counter|divisibleby:picsinrow %}right{% else %}middle{% endif %}{% endif %}"> 
      {% if story.image %} 
       {% thumbnail story.image size crop="center" as full_im %} 
        <a rel="gallery" href="{% url post slug=story.slug %}"> 
         <img class="preview" {% if story.title %} alt="{{ story.title }}" {% endif %} src="{{ full_im.url }}"> 
        </a> 
       {% endthumbnail %} 
      {% else %} 
       {% if story.image_url %} 
        {% thumbnail story.image_url size crop="center" as full_im %} 
         <a rel="gallery" href="{% url post slug=story.slug %}"> 
          <img class="preview" {% if story.title %} alt="{{ story.title }}" {% endif %} src="{{ full_im.url }}"> 
         </a> 
        {% endthumbnail %} 
       {% endif %} 
      {% endif %} 

     </div> 

</div> 

<script> 
    $(document).ready(function(){ 
     $(".image a").click(function(){ 
      alert($(this).parent().html()); 
     }); 

     $(".image a").fancybox({ 
      title: $(this).attr("alt"), 
      content: $(this).parent().html() 
     }); 
    }); 
</script> 

問題是,的fancybox加載錨的href的HTML,而不是HTML我通過在內容,它提醒正確。

這是怎麼回事?

回答

0

不幸的是你不能使用$(this)的的fancybox(v1.3.x)的功能(這是一個設計問題)內,但是任何其它的jQuery方法內部,試試這個

$(document).ready(function(){ 
$(".image a").bind("click",function(){ 
    var data = $(this).parent().html(); 
    var dataTitle = $(this).attr("alt"); 
    function newTitle(){return "<span>"+dataTitle+"</span>";} 
    $.fancybox(data,{ 
    "titlePosition": "inside", 
    "titleFormat": newTitle 
    }); // fancybox 
    return false; 
}); // bind 
}); //ready 
0

我認爲,這將工作:

$(".image a").click(function(){ 
     $.fancybox($(this).parent().html(),{ 
      title: $(this).attr("alt") 
     }); 
    }); 
+0

沒了,同樣的結果:( – Colleen 2012-04-05 20:39:06

+0

嗯,它的工作原理在這裏http://jsfiddle.net/hNfjC/或者不是你所期待的嗎?也許你做別的事情了? – 2012-04-05 20:43:35

+0

那是什麼我預料到了,所以我想我正在做其他事情......但我不知道是什麼。 – Colleen 2012-04-05 20:49:40