You can use document.getElementById('divId').className.split(/\s+/);
(您可以使用document.getElementById('divId').className.split(/\s+/);
)
to get you an array of class names.(给你一个类名数组。)
Then you can iterate and find the one you want.(然后,您可以迭代并找到所需的那个。)
var classList = document.getElementById('divId').className.split(/s+/);
for (var i = 0; i < classList.length; i++) {
if (classList[i] === 'someClass') {
//do something
}
}
jQuery does not really help you here...(jQuery并没有真正帮助您...)
var classList = $('#divId').attr('class').split(/s+/);
$.each(classList, function(index, item) {
if (item === 'someClass') {
//do something
}
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…