我正在构建一个将 div 注入站点的代码。问题是我无法通过 javascript 分配 css 值,因为它们似乎没有发生在文档上(不是全部)。
这是代码:
var barRoot = document.createElement('DIV');
barRoot.style.backgroundColor='#44AA44';
barRoot.style['height']='30px';
barRoot.style['width']='100%';
barRoot.style['position']='absolute';
barRoot.style['font-size']='14px';
barRoot.style['font-family']='Arial, Helvetica, sans-serif';
barRoot.style['z-index']='99999001';
barRoot.style['font-weight']='bold';
barRoot.style['top']='0pt';
barRoot.style['left']='0pt';
barRoot.style['color']='White';
barRoot.style['padding']='0pt';
barRoot.style['margin']='0pt';
barRoot.style['border']='0px solid rgb(0, 0, 0)';
barRoot.id = 'irobRootElem1';
document.body.insertBefore(barRoot, document.body.firstChild);
var heartImg = document.createElement('IMG');
heartImg.src = 'heart.png';
heartImg.style['float']='left';
heartImg.style['margin-left']='8px';
heartImg.style['margin-top']='5px';
heartImg.style['margin-right']='8px';
barRoot.appendChild(heartImg);