0

我必须将一些 li 元素添加到 ul 列表中。每个 li 元素包含:

  • 一个锚

  • 一个 img 标签

问题是图像不显示。

JSFiddle:http: //jsfiddle.net/michelejs/hxA9r/

function echoImages(json) {
    alert(json);
    var obj = $.parseJSON(json);
    var html = "";
    $.each(obj, function() {
        html += '<li id ="menu_travel-store" class="space ">' + '<a href="' + this['redirectURL'] + '">' + '<img src="' + this['imageURL'] + '" />' + this['description'] + '</a>' + '</li>';
    });
    alert(html);
    $("#cityOffers").append(html);
}​

我已经看到 Chrome 添加了这个 css 属性:

display: none !important;
visibility: hidden !important;
opacity: 0 !important;
background-position: 0px 0px;

但是如果我使用开发人员工具删除它,图像仍然不会显示。

问题是什么?谢谢。

4

3 回答 3

2

解决了,问题是 AdBlock Chrome 扩展阻止图像加载.....

于 2012-12-19T11:58:55.903 回答
0

你使用了错误的 jQuery 函数使用

$("#cityOffers").html(html);

代替

$("#cityOffers").append(html);

html() 期望一个包含 HTML 代码的字符串,而 append() 期望一个 dom 对象

于 2012-12-19T11:44:01.123 回答
0

我在firefox中测试过,它可以工作。

我已经更好地构建了您的代码。

http://jsfiddle.net/hxA9r/4/

function echoImages(json) {
    alert(json);
    var obj = $.parseJSON(json);
    var html = "";
    $.each(obj, function () {
        html += '<li id ="menu_travel-store" class="space ">' + '<a href="' + this.redirectURL + '">' + '<img src="' + this.imageURL + '" />' + this.description + '</a>' + '</li>';
    });
    alert(html);
    $("#cityOffers").append(html);
}
$(document).ready(function () {
    data = '[{"id":"1","redirectURL":"http:\/\/www.judopassion.com\/affiliate\/images\/1.png","imageURL":"http:\/\/www.judopassion.com\/affiliate\/images\/1.png","title":"1","description":"1"},{"id":"3","redirectURL":"http:\/\/www.judopassion.com\/affiliate\/images\/3.png","imageURL":"http:\/\/www.judopassion.com\/affiliate\/images\/3.png","title":"3","description":"3"},{"id":"6","redirectURL":"http:\/\/www.judopassion.com\/affiliate\/images\/9.png","imageURL":"http:\/\/www.judopassion.com\/affiliate\/images\/9.png","title":"9","description":"9"},{"id":"2","redirectURL":"http:\/\/www.judopassion.com\/affiliate\/images\/2.png","imageURL":"http:\/\/www.judopassion.com\/affiliate\/images\/2.png","title":"2","description":"2"},{"id":"5","redirectURL":"http:\/\/www.judopassion.com\/affiliate\/images\/5.png","imageURL":"http:\/\/www.judopassion.com\/affiliate\/images\/5.png","title":"5","description":"5"},{"id":"4","redirectURL":"http:\/\/www.judopassion.com\/affiliate\/images\/4.png","imageURL":"http:\/\/www.judopassion.com\/affiliate\/images\/4.png","title":"4","description":"4"}]';
    echoImages(data);

});​

编辑:这听起来像是从主机访问图像的问题。我已经在多个新旧浏览器上进行了测试,并且运行良好。

于 2012-12-19T11:49:49.703 回答