newChat.style.setAttribute("width";100px");在内

What's wrong with newChat.style.setAttribute("width", "100px"); in content script?

本文关键字:quot 100px 在内 width style setAttribute newChat      更新时间:2023-09-26

这行得通:

newChat.style.width = "100px";

但是这个没有:

newChat.style.setAttribute("width", "100px");

都在一个函数内,在content.js (Google扩展内容脚本)。

第二个我得到:

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

style是CSSStyleDeclaration对象,它没有setAttribute方法。

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

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