更新时间:2023-01-16 13:01:43
如果你在每个
之外声明一个变量,它将是可访问的在每个
内:
If you declare a variable outside of the each
, it will be accessible inside the each
:
var yourArray = [];
$('.profile-nav ul li a').not('.apply').each(function() {
if($(this).hasClass('cur')) {
yourArray.push($(this).prop('class').split(' ')[0]);
}
});
//Here, yourArray will contain the strings you require.
虽然正如其他人所示,但有很多方法可以显着缩短代码。
Although as others have shown, there are ways to shorten your code significantly.