Javascript 什么';s newChat.style.setAttribute(“宽度”、“100px”)有问题;在内容脚本中?

Javascript 什么';s newChat.style.setAttribute(“宽度”、“100px”)有问题;在内容脚本中?,javascript,google-chrome-extension,Javascript,Google Chrome Extension,这项工作: newChat.style.width = "100px"; 但这一条没有: newChat.style.setAttribute("width", "100px"); 两者都在content.js(谷歌扩展内容脚本)中的一个函数中 第二个是: Uncaught TypeError: undefined is not a function content.js:112 createChat content.js:112 (anonymous function) content.j

这项工作:

newChat.style.width = "100px";
但这一条没有:

newChat.style.setAttribute("width", "100px");
两者都在content.js(谷歌扩展内容脚本)中的一个函数中

第二个是:

Uncaught TypeError: undefined is not a function content.js:112
createChat content.js:112
(anonymous function) content.js:137
m.event.dispatch jquery-1.11.1.min.js:3
r.handle

样式是一个
CSSStyleDeclaration
对象,它没有setAttribute方法

您想要使用元素的方法设置元素的
style
属性,或者使用
CSSStyleDeclaration
对象的方法设置特定的css属性

newChat.setAttribute("style", "width:100px;");
//or
newChat.style.setProperty("width","100px");