简体   繁体   English

“HTMLElement”类型上不存在属性“r”

[英]Property 'r' does not exist on type 'HTMLElement'

I'm trying to get the radius of a circle svg element but a error is coming in vs code:我正在尝试获取圆形 svg 元素的半径,但 vs 代码中出现错误:

actual code:实际代码:

const circle = document.getElementById('progress_circle');
const radius = circle.r.baseVal.value;

error:错误:

Property 'r' does not exist on type 'HTMLElement'.js(2339)

I'm using svelte, ts and vs code and I'm also a newbie in web dev .我正在使用 svelte、ts 和 vs 代码,而且我也是 web dev 的新手

Finally I got to a solution thanks to @aerial301感谢@aerial301,我终于找到了解决方案

const circle = document.getElementById('progress_circle');
const radius = +circle.getAttribute('r');

reference: Changing properties of SVG circle in HTML5/JS参考: 在 HTML5/JS 中更改 SVG 圆的属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM