IE中jQuery attr()的替代方案? [英] Alternative for jQuery attr() in IE?

查看:159
本文介绍了IE中jQuery attr()的替代方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,如果我错了,请纠正我,但我认为jQuery attr()在IE中不起作用。 (标记为wontfix )既然如此,最佳替代方案是什么?例如,这可以在任何地方工作,但IE:

Ok, correct me if I'm wrong, but I take it that jQuery attr() does NOT work in IE. (marked wontfix) That being the case, what is the best alternative? For example, this works everywhere but IE:

jQuery(document).ready(function($) {
    $('.airsrc').each(function() {
        var $this = $(this);
        var src = $this.attr('data-websrc');
        $this.attr('src', src);
    });
});

更新:哎呀......我意识到了这个问题。我实际上在基于CSS3媒体查询的 if 语句中有这个。 IE8或更低版本中本机不支持的媒体查询。 attr()绝对有效!

Update: Whoops...I realize the issue. I actually had this inside an if statement based on a CSS3 media query. Media queries that aren't natively supported in IE8 or lower. The attr() definitely works!

推荐答案

我使用 attr 一直在IE上使用 data - * 属性,我从来没有遇到过任何问题。 这是一个实时版本,仅在IE6,IE7和IE9中测试过。没有我的IE8盒子,但我再也没有问题。

I use attr with data-* attributes on IE all the time, I've never had a problem. Here's a live version, just tested in IE6, IE7, and IE9. Don't have my IE8 box handy, but again, I've never had a problem.

这篇关于IE中jQuery attr()的替代方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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