請大家?guī)臀铱匆?,謝謝
<!DOCTYPE?HTML>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8">
<title>無標題文檔</title>
</head>
<body>
<script?type="text/javascript">
var?main?=?document.body;
//創(chuàng)建鏈接
function?createa(url,text)
{
????var?btn?=?document.createElement("a");
????btn.setAttribute("href",url);
????btn.setAttribute("value",text);
????//btn.setAttribute("color","red");
????btn.style.color="red";
????main.appendChild(btn);
}
//?調(diào)用函數(shù)創(chuàng)建鏈接
createa("http://idcbgp.cn","慕課網(wǎng)");
</script>?
</body>
</html>這代碼哪里錯了呢?謝謝?
另外,用setAttribute怎么設(shè)置顏色屬性???
2015-08-05
關(guān)鍵是沒在頁面上顯示你寫的這個鏈接,?btn.setAttribute("value",text);這塊不能這么寫,應(yīng)該用innerHTML來做。你是要設(shè)置背景色?還是設(shè)置字體顏色?
2015-08-05
顏色設(shè)置的話要寫?btn.setAttribute("style","color:red");