首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

getAttribute不能在IE中返回类?

在Internet Explorer中,getAttribute方法可能无法正确返回类名。为了解决这个问题,您可以使用className属性来获取元素的类名。以下是一个示例:

代码语言:javascript
复制
function getClass(element) {
  if (element.getAttribute("class")) {
    return element.getAttribute("class");
  } else {
    return element.className;
  }
}

这个函数将尝试使用getAttribute方法获取类名,如果失败,则使用className属性。这样,您可以在Internet Explorer中正确获取类名。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券