正在检测SVGAnimatedString的类名
Detecting classname of SVGAnimatedString
本文关键字:SVGAnimatedString 检测 更新时间:2023-09-26
我在构建SVG映射时遇到问题g上的onmouseover不起作用。我当时使用
window.onmouseover=function(e) {
console.log(e.target.className);
};
查看类名是否有任何问题,然后发现系统检测到的不是我使用的类名
SVGAnimatedString {animVal: "", baseVal: ""}
这是我使用类似代码数百次之前从未发生过的事情。知道如何在mouseover上获得g元素的实际类名吗?感谢
最简单的方法:
e.target.className.baseVal
另一种方式:
e.target.getAttribute("class")
确保在svg路径标记中也设置了类名,然后尝试e.target.getAttribute("class")
这对我很有效。
相关文章:
- 没有找到相关文章