使用for循环选择元素时,例如:
jQuery('[data-slide=' + slideInfo[index].hideIDs[i] + ']').slideUp()
这是我得到的错误。
看起来它是从某个地方而不是slideInfo[index].hideIDs[i]
jquery-1.11.3.min.js:2 Uncaught Error: Syntax error, unrecognized expression: [data-slide1=function each(iterator, context) {
try {
this._each(iterator, context);
} catch (e) {
if (e != $break) throw e;
}
return this;
}]
以下是完整代码:
var slideInfo = [
{
hideIDs: [0,1,2],
showIDs: [3,4,5]
},
{
hideIDs: [3,4,5],
showIDs: [6,7,8]
}
]
jQuery('[data-slide] [type=button]').on('click', function() {
for(var i in slideInfo[index].hideIDs) {
jQuery('[data-slide=' + slideInfo[index].hideIDs[i] + ']').slideUp();
}
for(var i in slideInfo[index].showIDs) {
jQuery('[data-slide=' + slideInfo[index].showIDs[i] + ']').slideDown();
}
index++;
});