A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

人来人往

初级黑马

  • 黑马币:

  • 帖子:

  • 精华:

© 人来人往 初级黑马   /  2014-1-17 10:32  /  992 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

var spanid=null;
var imgstatue=null;
function show(node){
        $(".pro_a").live("click",function(){
                         spanid = $(this).attr("id");
                             var imgSrc = node.currentStyle.backgroundImage;
                      imgSrc = imgSrc.slice(5,imgSrc.length-2);
                      imgstatue= imgSrc.substring(imgSrc.length-6,imgSrc.length);
                 
            });
        if(spanid!=null){
            if(imgstatue=="p1.png"|imgstatue==null&imgstatue!="p2.png"){
                   document.getElementById(spanid).style.backgroundImage="url(image/p2.png)";
                }else{
                           document.getElementById(spanid).style.backgroundImage="url(image/p1.png)";
                }
        }
}
获取当前ID下的背景图并改变

评分

参与人数 1技术分 +1 收起 理由
黄晓鑫 + 1

查看全部评分

1 个回复

倒序浏览
本帖最后由 qisikudingcha 于 2014-1-17 12:04 编辑

你是不是用火狐测试的 currentStyle的这个属性是ie的属性,

  1. <P>

  2. //var imgSrc = node.currentStyle.backgroundImage这句话可以这样改
  3. //判断如果是ie
  4. if(node.currentStyle){
  5.                                  imgSrc = node.currentStyle.backgroundImage;
  6.                          }else{</P>
  7. <P>  //getComputedStyle(node,false),这个方法等效于currentStyle,第一个参数填你要操作的对象,第二个一般填false,为了兼容老版本火狐
  8.                                 imgSrc = getComputedStyle(node,false).backgroundImage;
  9.                                 
  10.                          }</P>
复制代码

评分

参与人数 1技术分 +1 收起 理由
黄晓鑫 + 1

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马