我正在创建一个包含图像的React项目。
在我的项目中,我想得到上传图像的宽度和高度。
我用的是
const image = document.getElementById("inputimage");
const width = Number (image.width);
const height = Number (image.height);
console.log( width, height );
另一页中的图像标签
<img id='inputimage' alt='image' src={imageUrl} width="500px" height="auto" />
在这里
Number()
用于转换
image.width
和
image.height
转化成数字以备将来计算。
每当我运行这段代码时,我都没有得到输出。
const image = document.getElementById("inputimage");
const width = image.width;
const height = image.height;
console.log( width, height );
但是当我移除
编号()
然后我得到了输出。
有人知道为什么我在
编号()
使用了什么?
我能做些什么来转换
形象宽度
和
形象身高
变成数字?