IT菜_鸟
2016-01-07 21:47
<!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;
//创建链接
function createa(url,text)
{
var x=document.createElement("a");
x.setAttribute("innerHTML",text);
x.setAttribute("href",url);
return x;
}
main.appendChild(createa("http://www.imooc.com","慕课网"));// 调用函数创建链接
</script>
</body>
</html>
<script type="text/javascript"> var main = document.body; //创建链接 function createa(url,text) { var x=document.createElement("a"); x.href=url; x.text=text; main.appendChild(x); } // 调用 createa("http://www.imooc.com","慕课网"); </script>
你可以在浏览器打开调试工具,里面可以看出一部分问题
function createa(url,text){ var x=document.createElement("a"); x.innerHTML = text; //x.setAttribute("innerHTML",text); x.href = url; //x.setAttribute("href",url); return x; }
JavaScript进阶篇
468192 学习 · 21891 问题
相似问题