Jquery addClass 函数在 IE7 中对于 td 元素失败
对于以下 HTML:
<td class="width2 padLeft" id="loading_45"> </td>
以下 JQuery:
$('#loading_45').addClass('loading');
使用以下 css 定义:
td.loading
{
background-image:url("../images/icon_loading_circle.gif");
background-position:left center;
background-repeat:no-repeat;
height:auto;
position:absolute;
text-align:center;
}
不会导致背景图像出现在 IE7 中(在 FF 中工作正常)
有人知道我做错了什么吗?
正如 Pointy 指出的,问题出在 css 中的position:absolute;定义应该被删除 感谢大家这么快的回复
For the following HTML:
<td class="width2 padLeft" id="loading_45"> </td>
the following JQuery:
$('#loading_45').addClass('loading');
With the following css definition:
td.loading
{
background-image:url("../images/icon_loading_circle.gif");
background-position:left center;
background-repeat:no-repeat;
height:auto;
position:absolute;
text-align:center;
}
does not cause the background-image to appear in IE7 (works fine in FF)
Does anyone have an idea what I am doing wrong?
As Pointy noted the problem was in the css the position:absolute; definition should be removed
Thanks all for answering so fast
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我确信“addClass”正在工作,因为它会将类添加到元素中,如果(如@Gaby 指出)您在正确的时间执行此操作。由于它可以在 Firefox 中运行,因此您可能可以。
我怀疑问题可能只是因为你的样式表吓坏了 IE7。将“position:absolute”放在表格单元格上可能会导致问题,例如使表格单元格呈现在完全错误的位置。当我尝试时,表格单元格始终呈现在页面的左上角,即使样式表未指定“顶部”或“左侧”。
尝试使用该类硬编码到表格单元格来测试您的页面,看看会发生什么。
I'm sure that "addClass" is working, in that it's adding the class to the element, if (as @Gaby notes) you're doing it at the right time. Since it works in Firefox, you probably are.
I suspect that the problem might simply be that your stylesheet is freaking IE7 out. Putting "position: absolute" on a table cell is likely to cause problems, like making the table cell render in completely the wrong place. When I try it, table cells always render in the upper left corner of the page, even though the stylesheet doesn't specify a "top" or "left".
Try testing your page with that class hard-coded onto the table cell and see what happens.
加载 DOM 后运行
确保代码在使用或
。同时确保元素的宽度/高度适合背景图像。
演示:http://www.jsfiddle.net/9PZZB/2/
make sure the code runs after the DOM is loaded using
or
Also make sure the elements has a width/height that will fit the background image.
Demo: http://www.jsfiddle.net/9PZZB/2/