attr() 在 IE 中不起作用 [英] attr() not working in IE
问题描述
在这里浏览了一些类似的问题后,我找不到任何可以帮助我解决问题的内容.在 Chrome 中它可以工作,进入 IE,我得到aN,AN,NAN"
HTML
<div class="prev"><a class="prevMonth" name="05,27,2013">月</a>
jQuery
$(".dateSelect a").click(function(event){var dateParam = $(this).attr('name');alert("链接被点击,NAME 的值为:"+dateParam);日期更改(日期参数);事件 = 事件 ||窗口事件;event.stopPropagation();});
在 Chrome 中,它获取日期05,27,2013",但在 IE 中它是aN,aN,NaN"我偷偷地怀疑 IE 不喜欢 attr().如果是这种情况,是否有替代方法?提前谢谢你!
name
和 id
有相同的规则,不能以数字开头且没有特殊字符, 并且 IE 讨厌它...
在这种情况下,使用 data-
属性,例如:
月
并从您的脚本中获取它:
$(this).attr("data-name")
或 $(this).data("name")
.
它甚至适用于 IE6(如果您仍在使用 jQuery 1.x 版):)
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"
the HTML
<div class="dateSelect">
<div class="prev">
<a class="prevMonth" name="05,27,2013">month</a>
</div>
</div>
the 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();
});
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
has the same rules as id
, can't start with a number and no special chars, and IE hates it...
in this case, use data-
attributes, like:
<a class="prevMonth" data-name="05,27,2013">month</a>
and from your script get it through:
$(this).attr("data-name")
or $(this).data("name")
.
it even works with IE6 (if you still using version 1.x of jQuery) :)
这篇关于attr() 在 IE 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!