为什么不IE进程此Javascript的任何版本? [英] Why won't any version of IE process this Javascript?

查看:90
本文介绍了为什么不IE进程此Javascript的任何版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是code,更改背景图片的JQ插件,在Chrome,FF,Safari浏览器,甚至我的两个智能手机工作正常。但不是IE浏览器。任何人都可以发现一个问题吗?

 <脚本类型=文/ JavaScript的>
$(文件)。就绪(函数(){
$(#超大型IMG)。ATTR({
          SRC:图像/ bg2.jpg
        });
    $(#超大型),ATTR($(IMG));
});
< / SCRIPT>


解决方案

IE是其对象文本的形成非常严格。很多时候,它不喜欢你把一个逗号的最后一个属性之后。因此,在这种情况下你的的src 属性逗号后会给IE适合,最臭名昭著的IE 6和; 7

  $(#超大型IMG)。ATTR({
          SRC:图像/ bg2.jpg//< - 注意属性值后面没有逗号,因为它是最后一个。
        });
    $(#超大型),ATTR($(IMG));
});

This is the code, changing a background image for a jQ plugin, Works fine on Chrome, FF, Safari and even my two smart phones. But not IE. Can anyone spot a problem?

<script type="text/javascript">
$(document).ready(function() {
$("#supersized img").attr({ 
          src: "images/bg2.jpg",
        });
    $("#supersized").attr($("img"));
});
</script>

解决方案

IE is very strict on its object literal formation. Many times it does not like you to put a comma after the last property. So in this instance the comma after your src property will give IE fits, most notoriously IE 6 & 7

$("#supersized img").attr({ 
          src: "images/bg2.jpg"  //<-- notice no comma after property value because it's the last one.
        });
    $("#supersized").attr($("img"));
});

这篇关于为什么不IE进程此Javascript的任何版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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