当我在chrome中尝试代码document.createElement("svg") instanceof SVGElement
时,它会返回false
。为什么呢?
答案 0 :(得分:9)
在任何上下文中创建像<svg>
这样的元素并且凭空创建一个未知元素。如果要创建SVG元素,请使用:
var a = document.createElementNS("http://www.w3.org/2000/svg", "svg");
现在,如果你比较:
var result = a instanceof SVGElement;
result
将是true
。
请参阅此 JSFiddle
中的工作示例