jQuery .each 在不同的浏览器上给出不同的结果,但没有错误。它计算的元素是错误的,但为什么呢?
我需要将某个元素的所有一个属性添加到一个数组中:
这是 html:
<a class="umb" name="/wordpress/images/custom-slideshow/image1.jpg">
<a class="umb" name="/wordpress/images/custom-slideshow/image2.jpg">
<a class="umb" name="/wordpress/images/custom-slideshow/image3.jpg">
这是 jQuery
var theImages = new Array();
$('.umb').each(function(){
theImages.push($(this).attr('name'));
});
alert(theImages.length);
,它会在不同的浏览器中提醒不同的数字
在 Firefox“15”中
在 IE8 中“3”
在 Chrome“6”中
在歌剧《3》中 在 Safari 中“12”
正确答案当然是“3”。无法弄清楚为什么会发生这种情况。
I need to add the one attribute of all of a certain element to an array:
Here is the html:
<a class="umb" name="/wordpress/images/custom-slideshow/image1.jpg">
<a class="umb" name="/wordpress/images/custom-slideshow/image2.jpg">
<a class="umb" name="/wordpress/images/custom-slideshow/image3.jpg">
Here is the jQuery
var theImages = new Array();
$('.umb').each(function(){
theImages.push($(this).attr('name'));
});
alert(theImages.length);
this alerts different numbers in different browsers
in Firefox "15"
in IE8 "3"
in Chrome "6"
in Opera "3"
in Safari "12"
The right answer is of course "3". Can't figure out why this is happening.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过快速测试,我在 Safari 5 中得到了 3,但这可能是因为不同的浏览器会尝试以不同的方式纠正未闭合的锚标记(假设这不是粘贴错误)。每个锚应该有一个 在最后。
Well on a quick test of this I get 3 in Safari 5, but it could be because different browsers will attempt to correct the unclosed anchor tags in different ways (assuming that wasn't a paste error). Each anchor should should have a </a> at the end.