2013-08-21 82 views
0

我想要得到標題爲h1,h2,h3,h4,h5,h6的字體大小,它們分別是36px, 30px, 24px, 18px, 14px, 12px [in bootstrap.css]並在控制檯中提醒它們。我見過的jQuery方法是$('element').css('property'),但這不適用於外部css [即bootstrap.css]。 我是否需要添加更多的代碼行。使用JavaScript/jQuery從Bootstrap css獲取css值?

+0

你爲什麼要這麼做? –

+0

我通過表單輸入字符串,並希望在文本框中具有從h1到h6的字符串的所有類型的標題。 – Lonely

+0

爲什麼你想知道CSS屬性值 –

回答

0
$.each(['h1','h2','h3','h4','h5','h6'], function(idx, val){ 
    console.log($(val).css('font-size')) 
}); 
+0

OP提到這種方法在原始問題中不起作用。 – dc5

0
var stylesheet = document.styleSheets[(document.styleSheets.length - 1)]; 

for(var i in document.styleSheets){ 
    var temp = = document.styleSheets[i]; 
    if(temp.href && temp.href.indexOf("bootstrap.css")) { 
     stylesheet = temp; 
     break; 
    } 
} 
var ruleList = stylesheet.cssRules, allRules = []; 
for (var rule = 0; rule < ruleList.length; rule ++){ 
    allRules.push([rule, ruleList[rule].selectorText]); 
} 
console.log(addRules);