Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何对fancybox内容使用jquery.html()_Javascript_Jquery_Html_Django_Fancybox - Fatal编程技术网

Javascript 如何对fancybox内容使用jquery.html()

Javascript 如何对fancybox内容使用jquery.html(),javascript,jquery,html,django,fancybox,Javascript,Jquery,Html,Django,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 "submis

我的档案:

<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>

{%在section=“photos”%%中包含“submission form.html”
{%加载缩略图%}
{对象%中故事的百分比}
{%if story.image%}
{%thumbnail story.image size crop=“center”作为完整\u im%}
{%endthumbnail%}
{%else%}
{%if story.image_url%}
{%thumbnail story.image\u url size crop=“center”作为完整\u im%}
{%endthumbnail%}
{%endif%}
{%endif%}
$(文档).ready(函数(){
$(“.image a”)。单击(函数(){
警报($(this.parent().html());
});
$(“.image a”).fancybox({
标题:$(this.attr(“alt”),
内容:$(this.parent().html())
});
});
问题是,fancybox正在加载锚的href的html,而不是我传递给内容的html,这会正确地发出警报


有什么事吗?

我想这个会有用的:

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

不幸的是,您不能在fancybox(v1.3.x)函数中使用
$(this)
(这是一个设计问题),但在任何其他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
$(文档).ready(函数(){
$(“.image a”).bind(“单击”),函数(){
var data=$(this.parent().html();
var dataTitle=$(this.attr(“alt”);
函数newTitle(){return”“+dataTitle+”“;}
$.fancybox(数据{
“标题位置”:“内部”,
“标题格式”:新标题
});//fancybox
返回false;
});//绑定
}); //准备好的

Hm,它在这里起作用了,这不是你所期望的吗?也许你做错了什么?这就是我所期望的,所以我猜我做错了什么。。。“但我不知道是什么。”科琳唯一不同的是父母。你想在Fancybox中介绍哪个元素?如果你在没有服务器代码的情况下提供真正的DOM,那就太麻烦了,因为这与这个问题无关。我想提出这个问题,但我认为,因为它是一个,它正在加载href。我找到了另一种方法,但我想我需要重新思考我的方法。你想只显示图像吗?