IE 中 jQuery attr() 的替代方案? [英] Alternative for jQuery attr() in IE?
问题描述
好的,如果我错了,请纠正我,但我认为 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!
推荐答案
我一直在 IE 上使用 attr
和 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屋!