检测 SVGAnimatedString 的类名 [英] Detecting classname of SVGAnimatedString
本文介绍了检测 SVGAnimatedString 的类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在构建 SVG 地图时遇到了问题,由g 上的 onmouseover 不起作用.我当时用了
I had a problem with a SVG map I was building, the functions triggered by onmouseover on g were not working. I used then
window.onmouseover=function(e) {
console.log(e.target.className);
};
查看类名是否有问题,然后发现不是我使用的类名,而是系统检测
to see if there was any problem with the classname, and then discovered than instead of the classname I was using, the system was detecting
SVGAnimatedString {animVal: "", baseVal: ""}
在我使用类似代码数百次之前从未发生过的事情.知道如何在鼠标悬停时获得 g 元素的实际类名吗?谢谢
Something that never happened to me before the hundreds of times I've used similar code. Any idea how can I get the actual classname of the g elements on mouseover? Thanks
推荐答案
最简单的方法:
e.target.className.baseVal
另一种方式:
e.target.getAttribute("class")
这篇关于检测 SVGAnimatedString 的类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文