終于可以了。。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無(wú)標(biāo)題文檔</title>
</head>
<body>
<script type="text/javascript">
var main = document.body;
//創(chuàng)建鏈接
function createa(url,text)
{
? ? var a = document.createElement("a");
? ? a.setAttribute("href",url);
? ? a.innerHTML=text;
? ? a.style.color='red';
? ? main.appendChild(a);
? ??
? ??
? ??
}
// 調(diào)用函數(shù)創(chuàng)建鏈接
createa("http://idcbgp.cn/","慕課網(wǎng)");
</script>?
</body>
</html>
2023-04-08
為啥這個(gè)a.innerHTML不能寫成:
a.setAttribute("innerHTML",text);