【ラインスタイルの取得から】
<div id = 'div1' style = "backgroud:red"> test </div> <script> var odiv = document.getElementById( 'div1'); //最初に要素タグを取得してスタイルを取得します。つまり、div1 console.log(odiv.style.background)を取得します。 //行の間でスタイルを取得できるように</script>
【統合スタイルの取得】
<html> <head> <style> .div2 {background:red; } </style> </head> <body> <div id = "div1"> test </div> <scrip> var odiv = document.getElementById( 'div1'); //最初に要素タグを取得してスタイルを取得します。つまり、div1 //console.log(getcomputedstyle(odiv、null).background)を取得します。 getComputedStyle( "element"、 "pseudoclass")は、計算後に得られたスタイルです。 2番目のパラメーターは擬似クラスです。ただし、nullが直接使用されていない場合、邪悪なIE8と前のものはそれをサポートしていなかったため、次の方法が必要です。 //console.log(currentstyle.background)これは、IE自体によってのみサポートされています。また、計算されたスタイルコンソール(window.getComputedStyle?getComputedStyle(ODIV、null).background:odiv.currentStyle)を取得します。 //クロスブラウザー互換性</script> </body> </html>【外部リンクスタイルの取得】
<html> <head> <link rel = "styleSheet" type = "text/css" href = "basic.css"/> //アウトラインリンクスタイルシート</head> <body> <body> <body> <div div = "div1"> var sheet = document.stylesheets [0] // console.log(rule.style.background)// redこの方法で、外部リンクスタイルシートで指定されたスタイルを取得できます</script> </body> </html>
【外側のリンクスタイルシート】
.div2 {background:red;}上記の記事のCSSインターラインスタイル、インラインスタイル、外部リンクスタイルを取得する簡単な方法は、編集者が共有したコンテンツ全体です。参照を提供できることを願っています。wulin.comをもっとサポートできることを願っています。