如何通过 JavaScript 在 属性 之前应用 css?

How to apply css before property via JavaScript?

`   input.star:checked ~ label.star:before {
            content: '\f005';
            color: #FD4;
            transition: all .25s;
        }    `

如何通过 javascript 应用此代码?

如果要用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);