請大家幫我看以,謝謝
<!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;
//創建鏈接
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);
}
//?調用函數創建鏈接
createa("http://www.xianlaiwan.cn","慕課網");
</script>?
</body>
</html>這代碼哪里錯了呢?謝謝?
另外,用setAttribute怎么設置顏色屬性啊?
2015-08-05
關鍵是沒在頁面上顯示你寫的這個鏈接,?btn.setAttribute("value",text);這塊不能這么寫,應該用innerHTML來做。你是要設置背景色?還是設置字體顏色?
2015-08-05
顏色設置的話要寫?btn.setAttribute("style","color:red");