2013-04-18 21 views
2

一個<風格的CSSStyleSheet對象>對應一個的CSSStyleSheet對象(document.styleSheets),但如何找到它,如對應<風格的id的CSSStyleSheet對象=「 - yCoder的樣式」> ... < /風格>如何從一個<style>

console.log(document.styleSheets.length); 

var style = document.createElement('style'); 
style.title = "-yCoder-styles"; 
style.type= 'text/css'; 
style.id = "-yCoder-styles"; 
document.head.appendChild(style); 

//how to get the corresponding CSSStyleSheet instance from document.styleSheets 

console.log(document.styleSheets.length); 

var styleSheet = document.styleSheets[document.styleSheets.length - 1]; 
console.log(styleSheet.title == style.title); 
+0

你爲什麼認爲它不起作用? http://jsfiddle.net/MKu5u/ – 2013-04-18 04:11:37

+0

我的代碼工作,因爲我知道風格是最後一個,但如果我只知道