Invalid assignment left-hand side with ternary if

前端 未结 2 1518
傲寒
傲寒 2021-01-12 15:53

I want to create an stylesheet like this:

var sheet = document.createElement(\'style\'); sheet.type = \'text/css\';
sheet.innerHTML = data.style;
         


        
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-12 15:58

    You can always do :

    sheet.styleSheet ? sheet.styleSheet.cssText = data.style 
                     : sheet.appendChild(document.createTextNode(data.style));
    

    FIDDLE

提交回复
热议问题