1. A simple method, regardless of whether or not, can directly do this:
Document.createstylesheet().css text = 'tag {color: red;' + // This annotation is only available in the current JS and will not be written to 'width: 300px; height: 150px} '+ '. class Name {......} '+' # IDs {......} ';
// Complete the job. I like writing with semicolons, which is better aligned with the starting position of instruction writing, especially when other statements are followed.
2. To prevent repeated addition, you can add a style sheet ID and determine the style sheet ID:
If (! Document. stylesheets ['id of the style table to be created, such as theforever ']) {// check whether the ID of the style table to be created exists to prevent repeated addition of VaR Ss = document. createstylesheet (); SS. owningelement. id = 'id of the style sheet to be created, such as theforever '; ss.css text =' tag {display: inline-block; overflow: hidden; '+ // This annotation can only be understood in the current JS, and will not be written to 'text-align: Left; width: 300px; Height: 150px}' + 'in CSS '. class Name {......} '+' # IDs {......} ';}