【发布时间】:2014-01-08 04:41:42
【问题描述】:
我有一个 jQuery 加载函数,可以使用 alt 标记数据创建和添加后图像。它适用于所有浏览器和 IE9,只是不适用于 IE10,我不知道为什么。
这是 jQuery 代码:
$("img.caption").load(function () {
var imageCaption = $(this).attr("alt");
if (imageCaption != '') {
var imgWidth = $(this).width();
$("<figcaption class='img-caption'><em>" + imageCaption + "</em></figcaption>").css({ "position": "relative", "bottom": 0, "left": 0, "width": imgWidth + "px" }).insertAfter(this);
}
var figcaptionHeight = $('.img-caption').outerHeight();
$('.img-caption').css('margin-top', -(figcaptionHeight + 2));
});
我什至尝试过使用其他标签,但根本没有任何响应。
这是 HTML 标记:
<figure>
<img class="caption" alt="caption text" />
</figure>
【问题讨论】:
-
你检查错误控制台了吗?
-
它说“选择器找到零个元素”,这让我感到困惑,因为其他所有浏览器都没有问题,而且它不像是一个复杂的选择器。
-
图片标签的
.src属性在哪里?它不会生成带有要实际加载的图像 URL 的load事件。
标签: jquery html internet-explorer-10