為什么沒有反應(yīng)?
<!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;
//創(chuàng)建鏈接
function createa(url,text)
{
? ?var a=createElement("a");?
? ?a.href=url;
? ?a.innerHTML=text;
? ? main.appendChild("a");
? ??
}
// 調(diào)用函數(shù)創(chuàng)建鏈接
main.createa("http://www.baidu.com","百度");
</script>?
</body>
</html>
2017-03-11
var a=createElement("a")這行代碼應(yīng)該寫成document.createElement("a");
main.appendChild(createa("http://www.baidu.com","百度"));才是正確的調(diào)用方法
function中需要返回return a;
將function中的main......去掉