Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.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 笑话:如何使用dom设置offsetWidth_Javascript_Html_Dom_Jestjs - Fatal编程技术网

Javascript 笑话:如何使用dom设置offsetWidth

Javascript 笑话:如何使用dom设置offsetWidth,javascript,html,dom,jestjs,Javascript,Html,Dom,Jestjs,如何设置,因为HTMLElement.offsetWidth是只读属性。 当我试图强制执行预期的值时,出现以下错误 TypeError:无法设置只有getter的[object HtmleElement]的属性offsetWidth 然后我尝试了下面的方法,但不起作用。我也没有错误: document.querySelector('.a').setAttribute('offsetWidth', 600); 没关系,我找到了解决办法。您可以使用style.width: document

如何设置,因为
HTMLElement.offsetWidth
是只读属性。 当我试图强制执行预期的值时,出现以下错误

TypeError:无法设置只有getter的[object HtmleElement]的属性offsetWidth

然后我尝试了下面的方法,但不起作用。我也没有错误:

    document.querySelector('.a').setAttribute('offsetWidth', 600);

没关系,我找到了解决办法。您可以使用
style.width

document.querySelector('.a').style.width = '600px';