比方說這是我的javascript代碼:如何將css添加到Javascript中?
var bottomChild = document.createElement('div');
bottomChild.id = 'bottomChildId';
bottomChild.style.width = '100px';
bottomChild.style.position = 'relative';
bottomChild.style.overflowY = 'scroll';
bottomChild.style.background = 'red';
bottomChild.style.top = '0px';
bottomChild.style.borderLeft = '0px solid #E4E7EA';
bottomChild.style.height = '200px';
document.body.appendChild(bottomChild);
現在我想下面的CSS添加到bottomChild:
::-webkit-scrollbar {
width: 22px;
}
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
-webkit-border-radius: 10px;
border-radius: 10px;
}
請添加這些CSS成動態JavaScript DIV幫助。
可能重複的顯示在[內聯樣式的CSS僞類](http://stackoverflow.com/questions/5293280/css-pseudo-classes-with-inline-styles) –
document.querySelector('style')。textContent + = ' :: - webkit-scrollbar { width:22px; } :: - webkit-scrollbar-track { -webkit-box-shadow:inset 0 0 6px rgba(0,0,0,0.3); -webkit-border-radius:10px; border-radius:10px; }' –