attr()不在IE中工作 [英] attr() not working in IE
问题描述
在这里浏览了一些类似的问题后,我找不到任何可以帮助我解决问题的方法。在Chrome中它可以工作,进入IE并获得aN,AN,NAN
after browsing some similar question on here I couldn't find anything to help me fix my problem. In Chrome it works, get to IE and I get "aN,AN,NAN"
HTML
<div class="dateSelect">
<div class="prev">
<a class="prevMonth" name="05,27,2013">month</a>
</div>
</div>
jQuery
$(".dateSelect a").click(function(event){
var dateParam = $(this).attr('name');
alert("link was clicked and value of NAME is: "+dateParam);
dateChange(dateParam);
event = event || window.event;
event.stopPropagation();
});
在Chrome中,它抓住了日期05,27,2013,但IE浏览器是aN,aN, NaN
我有一种偷偷摸摸的怀疑IE不喜欢attr()。如果是这样的话,还有另一种方法吗?提前谢谢!
In Chrome it grabs the date "05,27,2013" but IE it's "aN,aN,NaN" I have a sneaky suspicion IE doesn't like attr(). If that's the case, is there an alternative way? Thank you in advance!
推荐答案
name
与 id
,不能以数字开头且没有特殊的字符,而且IE讨厌它......
name
has the same rules as id
, can't start with a number and no special chars, and IE hates it...
case,使用 data -
属性,例如:
in this case, use data-
attributes, like:
<a class="prevMonth" data-name="05,27,2013">month</a>
并从您的脚本中获取:
$(this).attr(data-name)
或 $(this).data(name)
。
它甚至适用于IE6(如果你仍然使用jQuery的1.x版本):)
it even works with IE6 (if you still using version 1.x of jQuery) :)
这篇关于attr()不在IE中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!