代码如下,如果是class则取出的颜色值是空,但如果直接用style则正确,不知怎么解决
<html>
<head>
<style type="text/css">
p.ci_1 {
color: #80FF80;
}
</style>
<script type="text/javascript">
function setColor()
{
var g_all = document.getElementsByTagName("p");
var n = g_all.length;
for (var i = 0; i < n; i++)
{
// g_all[i].style.color="#80FF80";
alert("aa--"+g_all[i].style.color+"--bb");
}
}
</script>
</head>
<body>
<p class='ci_1'>This is an example paragraph.</p>
<p style='color: #80FF80' >This is also an example paragraph.</p>
<input type="button" onclick="setColor()" value="Change color of text" />
</body>
</html>
守着一只汪
相关分类