setAttribute("color","red");和style.color="red"效果為什么不一樣?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標(biāo)題文檔</title>
</head>
<body>
<script type="text/javascript">
var main = document.body;
//創(chuàng)建鏈接
function createa(url,text)
{
? ?var newnode=document.createElement("a");
? ?newnode.innerHTML=text;
? ?newnode.href=url;
? ?//newnode.style.color="red"
? ?newnode.setAttribute("color","red"); //不能實(shí)現(xiàn)文字紅色效果
? ?main.appendChild(newnode) ?
}
// 調(diào)用函數(shù)創(chuàng)建鏈接
createa("http://idcbgp.cn/","慕課網(wǎng)");
</script>?
</body>
</html>
2016-07-16
newnode.setAttribute('style', 'color:red');