App下載
首頁javascriptbackgroundjQuery Style - 如何讀取/獲取CSS背景顏色

jQuery Style - 如何讀取/獲取CSS背景顏色

我們想知道如何讀取/獲取CSS背景顏色。

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'>
$(window).load(function(){
    console.log($('#div1')[0].style.backgroundColor);
});
</script>
</head>
<body>
  <div id="div1" style="background-color: red">asdf</div>
</body>
</html>