` input.star:checked ~ label.star:before {
content: '\f005';
color: #FD4;
transition: all .25s;
} `
如何通过javascript应用此代码?
答案 0 :(得分:2)
如果你想用js添加一个样式,你可以使用style.sheet的insertRule()
,示例代码:
var sheet = (function() {
// Create the <style> tag
var style = document.createElement("style");
// WebKit hack :(
style.appendChild(document.createTextNode(""));
// Add the <style> element to the page
document.head.appendChild(style);
return style.sheet;
})();
// for a test
sheet.insertRule("body { background-color:red;}", sheet.length);
// for your code just replace param
// sheet.insertRule("input.star:checked ~ label.star:before {content: '\f005';color: #FD4;transition: all .25s;}}", sheet.length);