<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style type="text/css">
#div {
height:400px;
width:400px;
border:1px solid blue;
background-color:red;
}
</style>
<script type="text/javascript">
var exec1 = function () {
//get the backgroundcolor
var bkcolor = document.getElementById("div").style.backgroundColor ||"rgb(255,0,0)"; //这个方法不行额 前面的那个一定是space
alert(bkcolor);
//alert(document.getElementById("div").currentStyle.backgroundColor);
document.write(document.getElementById("div").currentStyle.backgroundColor);
}
onload = function () {
exec1();
}
</script>
</head>
<body>
<input type="submit" id="btn" value="淡出" />
<div id="div">
</div>
</body>
</html>
JS获取CSS颜色值
最新推荐文章于 2024-01-05 10:59:42 发布