jiuwei
2016-11-01 19:42:47
var main = document.body;//創(chuàng)建鏈接function createa(url,text){? ?var a = document.createElement("a");? ?a.setAttribute("href",url);? ?a.setAttribute("a.innerHTML","text");? ?a.setAttribute("a.style.color","red");? ? main.appendChild(a);}// 調用函數(shù)創(chuàng)建鏈接createa("http://idcbgp.cn","慕課網(wǎng)");
1 回答

咕咕問
TA貢獻78條經(jīng)驗 獲得超12個贊
? ?a.setAttribute("a.innerHTML","text");
? ?a.setAttribute("a.style.color","red");
setAttribute 前面是屬性名 ? 后面是屬性值
innerHTML 被解析為屬性名了
style="color:red;"
<!DOCTYPE html>
<html>
<body>
<script>
var main = document.body;
//創(chuàng)建鏈接
function createa(url,text)
{
? ?var a = document.createElement("a");
? ?a.setAttribute("href",url);
? ?a.innerHTML = text;
? ?a.setAttribute("style","color:red;");
? ? main.appendChild(a);
}
// 調用函數(shù)創(chuàng)建鏈接
createa("http://idcbgp.cn","慕課網(wǎng)");
</script>
</body>
</html>
添加回答
舉報
0/150
提交
取消