使用JavaScript/jQuery从引导css获取css值?

使用JavaScript/jQuery从引导css获取css值?,javascript,jquery,twitter-bootstrap,Javascript,Jquery,Twitter Bootstrap,我想获得标题h1、h2、h3、h4、h5、h6的字体大小,它们分别是[bootstrap.css]中的36px、30px、24px、18px、14px、12px,并在控制台中发出警报。我看到的jQuery方法是$('element').css('property'),但这不适用于外部css[I.e bootstrap.css]。 我是否应该包含更多的代码行。var stylesheet=document.styleSheets[(document.styleSheets.length-1)];

我想获得标题
h1、h2、h3、h4、h5、h6
的字体大小,它们分别是[bootstrap.css]中的
36px、30px、24px、18px、14px、12px
,并在控制台中发出警报。我看到的jQuery方法是
$('element').css('property')
,但这不适用于外部css[I.e bootstrap.css]。 我是否应该包含更多的代码行。

var stylesheet=document.styleSheets[(document.styleSheets.length-1)];
$.each(['h1','h2','h3','h4','h5','h6'], function(idx, val){
    console.log($(val).css('font-size') )
});
for(document.styleSheets中的var i){ var temp==document.styleSheets[i]; if(temp.href&&temp.href.indexOf(“bootstrap.css”)){ 样式表=温度; 打破 } } var ruleList=stylesheet.cssRules,allRules=[]; 对于(变量规则=0;规则
为什么要这样做?我正在通过表单输入一个字符串,并希望该字符串的所有类型的标题(从h1到h6)都位于文本框中。为此,为什么要知道css属性值,然后我可以将该值赋给font size$textarea.css(“font-size”,value);哦,我刚刚认识到,如果我这样做,文本框的字体大小将是固定的,有没有办法做到这一点。OP提到这个方法在最初的问题中不起作用。
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);