【发布时间】:2012-05-10 17:47:19
【问题描述】:
http://jsfiddle.net/suenot/3b3XM/1/
// in FF and IE each() don't work offset()
// $(this).offset().top return empty string
$(document).ready(function(){
var index = 0;
$('.box').each(function(){
var background = $(this).css('background');
$(this).css('background', 'none');
var height = $(this).css('height');
var top = $(this).offset().top;
$('body').prepend('<div id="box' + ++index + '"></div>');
$('#box' + index).css({
'height': height,
'background': background,
'position': 'absolute',
'z-index': '-1',
'top': top,
'width': '100%'
});
});
});
请帮帮我,我找不到解决方案。
【问题讨论】:
-
刚刚在 FF 12 中测试过,它工作正常
.offset().top返回一个值。 -
在 each() 中测试了吗?在jsfiddle中也可以吗?对不起我的英语。
-
请贴一些代码sn-ps,而不仅仅是一个链接。
-
问题是
$(this).css('background')返回一个空字符串。 -
正如 Rocket 所指出的 -> 似乎
$(this).css('background')在 IE 9 和 Chrome 中运行良好,但在 FF 12 中失败,$(this).css('background-color');似乎适用于所有三种浏览器。
标签: javascript jquery firefox each offset