问答详情
源自:9-16 创建元素节点createElement

提交完全无反应

<!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 addhref=document.createElement("a");
    addhref.setAttribute("href",url);
    addhref.setAttribute("text","http://www.immoc.com");
    addhref.setAttribute("color",red);
    main.appendChild(addhref);
    
}
// 调用函数创建链接
    createa("http://www.imooc.com/","慕课网");

</script>
</body>
</html>

提问者:qq_封Y_0 2015-08-10 16:49

个回答

  • J丶_0
    2015-08-10 23:20:08

    red应该是"red"

    addhref.setAttribute("color","red");
    addhref.innerHTML = "imooc";//加一句这个