Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript getBBox函数从动态创建的文本SVG节点返回属性为零的对象_Javascript_Svg - Fatal编程技术网

Javascript getBBox函数从动态创建的文本SVG节点返回属性为零的对象

Javascript getBBox函数从动态创建的文本SVG节点返回属性为零的对象,javascript,svg,Javascript,Svg,我想获得动态创建的文本SVG节点的宽度。这是我的代码片段 var textSvgElement = document.createElementNS('http://www.w3.org/2000/svg','text'); textSvgElement.setAttribute('style', '12px'); textSvgElement.setAttribute('x', '10'); textSvgElement.setAttribute('y', '20'); textSvgElem

我想获得动态创建的文本SVG节点的宽度。这是我的代码片段

var textSvgElement = document.createElementNS('http://www.w3.org/2000/svg','text');
textSvgElement.setAttribute('style', '12px');
textSvgElement.setAttribute('x', '10');
textSvgElement.setAttribute('y', '20');
textSvgElement.appendChild(document.createTextNode('some text'));
var textSvgElementDataObj = textSvgElement.getBBox();
但是
textsvegelementdataobj
变量始终包含具有零值属性的对象,如图像上的:


有谁能给我一些解决这个问题的建议吗?

先将文本附件附在文档上。

@RobertLongson,谢谢!很好用!