getStyle(),修改样式属性

时间:2024-07-26 09:03:02
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head> <body>
<style>
#div{ width:100px; height:100px; background-color:#F00}
</style>
<div id="div"></div>
<script>
var obj = document.getElementById('div')
alert(getStyle(obj, 'backgroundColor')); function getStyle(obj, name)
{
if(obj.currentStyle)
{
return obj.currentStyle[name];
}
else
{
return getComputedStyle(obj,false)[name];
}
}
</script>
</body>
</html>

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQIAAACwCAIAAABrWPfNAAAKlklEQVR4nO2cz08bRx+H989xFCT+ATdJe6C5AYrkHir+gO2ZJLf4JXCB2N4fMyNE36RR+9I7SDQiVaNWBfQe2iTkrZMiUK6vlBLrLU57SHOY97D22tjrBbzjOh6eR1ZY1vtZj9B8d2a8+8RRSgWh9PxQSqWU8gPhB0IpJZXy/DAIpVJKSFXxglBIpVQoZMULhFQECVoTdFpHqMQjxMmnJkhwxINOxfPjEvH8QCmllPL8oHGcVBXPj+osFKpc8ULROClBgtYEHc8Pm+Ui/EBIpaRSfiDi2vL8MGjUlqr4QePUQhIkaE3QiUqk4vnNEgk9P4y2K54fl0up3BhdAiFLZU80a4sgQQuCjbWBHwghlZQqCGUQCimVkFG5NGrLD8Kottq3CRK0I+iUyl5cInG5VDw/LpdS2YvGjlCopVI5PilBgtYEnSAUoVBSqkDIIJRCKhGVi5BSqlCoIBRhc9sPGgeHQhIkaE2wsTaIy6XiBRUviGvLD0KllJRqqVSO51tLpXK87iZI0IKgEwoVChUIGW2EQobN7badjW0hk/cTJDjSQWepVG6UiB+UKo1yKVe8SvPr1aVSOVqDC6kWl+6EQiml/FAQJGhN8GyjQeo2QYKjGuxrbXCn34kaQYLvZdAJwsZEKuhaRN+998XCwoILM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