首页
学习
活动
专区
圈层
工具
发布

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中正确获取类名。

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

相关·内容

没有搜到相关的文章

领券