简体   繁体   English

twitter bootstrap模式不显示远程图像

[英]twitter bootstrap modal not displaying remote image

I'm using twitter bootstrap's modal window to load a remote image 我正在使用twitter bootstrap的模态窗口来加载远程图像

<a href="assets/500x300.gif" data-target="#image-preview" data-toggle="modal"><img alt="250x150" src="/assets/250x150.gif"></a>

I'm following these docs 我正在关注这些文档

The image is not rendering correctly in the modal. 图像在模态中无法正确渲染。

I get a load of jumbled data instead - 我得到了大量混乱的数据 -

twitter bootstrap不是很好

What's happening? 发生了什么? How can I fix? 我该怎么办?

Yes, I had this too. 是的,我也有这个。 The answer I found is here . 我找到的答案就在这里

I created a link like this: 我创建了一个这样的链接:

<a href="gallery/blue.jpg" class="thumbnail img_modal">

//handler for link
$('.img_modal').on('click', function(e) {
    e.preventDefault();
    $("#modal_img_target").attr("src", this);
    $('#modal').modal('show');
});

//and modal code here

<div id="modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">Title to go here</h3>
    </div>
    <div class="modal-body">
        <img id="modal_img_target">
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    </div>
</div>

When using href to specify remote content for a modal, Bootstrap uses jQuery's load method to fetch the content, and then sticks the retrieved content into the modal's body element. 当使用href为模态指定远程内容时,Bootstrap使用jQuery的加载方法来获取内容,然后将检索到的内容粘贴到模态的body元素中。 In short, it only makes sense when the remote content (the href value) loads HTML or text. 简而言之,只有在远程内容(href值)加载HTML或文本时才有意义。

What you're seeing is expected, as it's the same thing that would happen if you opened the gif file in a text editor, and just pasted it into an HTML tag. 您所看到的是预期的,因为如果您在文本编辑器中打开gif文件并将其粘贴到HTML标记中,就会发生同样的事情。

To have it work the way you want, the href needs to point to an HTML document that contains an <img> tag that references the image you want in the modal. 为了让它按照您想要的方式工作,href需要指向一个HTML文档,其中包含一个<img>标记,该标记引用了模式中所需的图像。

In post of Mark Robson – change 'this' to 'this.href': 在Mark Robson的帖子中 - 将'this'更改为'this.href':

 $("#modal_img_target").attr("src", this); 

=> =>

$("#modal_img_target").attr("src", this.href);

(I don't have reputation for comment) (我没有评论的声誉)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM