求大神告知,哪里出了問題?一直找不出來
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,"red");
? ?main.appendChild(a);
? ??
? ??
? ??
?}
?createa(" http://idcbgp.cn","慕課網(wǎng)");// 調(diào)用函數(shù)創(chuàng)建鏈接
2018-12-28
給你個參考
function createa(url,text)
{
? ? //var body =document.body;
? ? var a=document.createElement("a");
? ? a.href=url;
? ? a.innerHTML=text;
? ? a.style.color="red";
? ? main.appendChild(a);
? ? /*方法二
? ? var linktomk=document.createElement("a");
? ? linktomk.setAttribute("href",url);
? ? linktomk.innerHTML=text;
? ? main.appendChild(linktomk);*/
? ??
}
// 調(diào)用函數(shù)創(chuàng)建鏈接
createa(" http://idcbgp.cn/","慕課網(wǎng)");
2018-11-15
?a.setAttribute(style,"red");?setAttribute為設(shè)置屬性? 設(shè)置顏色 用 a.style.color = "red";就行; url加“”表示一個字符串里面存的url三個字符,不加“”表示為url這個參數(shù),為方法傳遞的參數(shù),在你這里存的是"http://idcbgp.cn";text對應(yīng)存的是"慕課網(wǎng)"
2018-11-09
個人理解
href,style是設(shè)置屬性名稱,要加上引號。url是傳遞的參數(shù),去了引號。