為什么出不來東西
<!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)
? ? {
? ? ? ? // 鏈接地址 http://idcbgp.cn,文本為:慕課網(wǎng)
? ? ? ? alert("000");
? ? ? ? var a=createElement("a");
? ? ? ? a.addAttribute("href",url);
? ? ? ? a.innerHTML=text;
? ? ? ? document.innerHTML=a;
? ? };
? ? // 調(diào)用函數(shù)創(chuàng)建鏈接
? ? createa("http://idcbgp.cn","慕課網(wǎng)");
</script>
</body>
</html>
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-09-25
var main = document.body;
function createa(url, text) {
? ? var a = document.createElement("a"); //? 你這里 createElement 方法是document對象下的,要加document
? ? a.setAttribute("href", url); //添加屬性的代碼是是setAttribute不是addAttribute
? ? a.innerHTML = text;
? ? main.appendChild(a); //添加節(jié)點的代碼是? main.appendChild(a) 不是 document.innerHTML=a
}
createa("http://idcbgp.cn", "慕課網(wǎng)");