在Internet Explorer中,getAttribute
方法可能无法正确返回类名。为了解决这个问题,您可以使用className
属性来获取元素的类名。以下是一个示例:
function getClass(element) {
if (element.getAttribute("class")) {
return element.getAttribute("class");
} else {
return element.className;
}
}
这个函数将尝试使用getAttribute
方法获取类名,如果失败,则使用className
属性。这样,您可以在Internet Explorer中正确获取类名。
领取专属 10元无门槛券
手把手带您无忧上云