数组返回一系列.box
的数组,其中一个数组有一个额外的类.logo
如何将数组中的整数应用于整数忽略该元素而不删除它? (不能使用.splice
,因为我需要.logo
留在阵列用于其他目的的)jQuery按类别忽略数组中的元素
所以我需要说:IF .logo
是数组的索引0-2内,则忽略它,并添加下一个整数
这是我目前使用的。这是冗长和丑陋:
var b = $('.box'), //Box
boxImgs = $('.box img'); // Box element images
if (b.eq(0).hasClass('logo')) {
boxImgs.eq(1).wrap('<a href="http://player.vimeo.com/video/34969501" />');
boxImgs.eq(2).wrap('<a href="http://player.vimeo.com/video/35036115" />');
boxImgs.eq(3).wrap('<a href="http://player.vimeo.com/video/35033574" />');
} else if (b.eq(1).hasClass('logo')) {
boxImgs.eq(0).wrap('<a href="http://player.vimeo.com/video/34969501" />');
boxImgs.eq(2).wrap('<a href="http://player.vimeo.com/video/35036115" />');
boxImgs.eq(3).wrap('<a href="http://player.vimeo.com/video/35033574" />');
} else if (b.eq(2).hasClass('logo')) {
boxImgs.eq(0).wrap('<a href="http://player.vimeo.com/video/34969501" />');
boxImgs.eq(1).wrap('<a href="http://player.vimeo.com/video/35036115" />');
boxImgs.eq(3).wrap('<a href="http://player.vimeo.com/video/35033574" />');
} else {
boxImgs.eq(0).wrap('<a href="http://player.vimeo.com/video/34969501" />');
boxImgs.eq(1).wrap('<a href="http://player.vimeo.com/video/35036115" />');
boxImgs.eq(2).wrap('<a href="http://player.vimeo.com/video/35033574" />');
}
最终会有更多的元素比网址(40到10)。这里是一个jsFiddle我设置了测试贾斯珀的想法:http://jsfiddle.net/danielredwood/MgFj2/6/ 我非常感谢你的帮助! – technopeasant 2012-03-02 20:53:28
一切都很好,即使有40个元素也能正常工作 – technopeasant 2012-03-02 21:04:34
因为这似乎是答案的其余部分打包成一个答案,但20分钟后发布... – Jasper 2012-03-02 21:15:11