动态切换“背景图片"在IE中不起作用 [英] dynamically switching 'background-image' doesn't work in IE

查看:244
本文介绍了动态切换“背景图片"在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的jquery位动态切换div的背景图像.在FF中可以正常工作,但在IE中却不能.有什么想法吗?如果更改了CSS属性,IE不会重新加载图像吗?任何指针将不胜感激.

I'm dynamically switching a div's background-image with the jquery bit below. Works just fine in FF, but turns out in IE it does not. Any ideas why? Does IE not reload the image if a css property changed? Any pointers would be appreciated.

$(function(){
   $('.header').each(function(){
      $(this).hover(function(){
         $('#headertab').css('background-image','url(/tab_'+$(this).attr('href').split('path=')[1]+'.gif');
      });
   });
}); 

推荐答案

尝试设置backgroundImage而不是background-image.

CSS属性在通过Javascript访问时,通常使用camelCase而不是破折号来避免语法问题. (element.style.background-image似乎在进行减法运算.)Firefox可能具有足够的渐进性,也允许使用破折号,但是IE ...似乎不行.

CSS attributes, when accessed via Javascript, traditionally use camelCase instead of dashes, to avoid questions of syntax. (element.style.background-image looks like you're doing subtraction.) Firefox is probably progressive enough to allow the dashes as well, but IE... it would seem not.

这篇关于动态切换“背景图片"在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆