スタイル、currentStyle、getComputedStyleの違い
612 ワード
エレメントに類似のスタイルを追加しない場合:style=「font-size:20 px;」異なるブラウザでスタイルの属性値を取得する方法:
動的に追加されたスタイル:
bodyセクションのテスト:
function test(){
var x = document.getElementById("t1");
//
if(x.currentStyle){//ie
var size = x.currentStyle['fontSize'];
alert(size);
}else if(window.getComputedStyle){//ff Google...
var size= window.getComputedStyle(x,null)['fontSize'];
alert(size);
}
}
動的に追加されたスタイル:
bodyセクションのテスト:
test