如何设置offsetWidth,因为HTMLElement.offsetWidth是只读属性.当我试图强制执行所期望的值时,我有以下错误。
TypeError:无法设置只有getter的对象HTMLElement的属性offsetWidth
然后我试了下面的方法,但不起作用。我也没有错误:
document.querySelector('.a').setAttribute('offsetWidth', 600);发布于 2020-10-28 10:41:07
没关系,我找到了解决办法。您可以使用style.width:
document.querySelector('.a').style.width = '600px';https://stackoverflow.com/questions/64570943
复制相似问题