marshall_stan
2015-08-04 13:18
<!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 btn = document.createElement("a");
btn.setAttribute("href",url);
btn.setAttribute("value",text);
//btn.setAttribute("color","red");
btn.style.color="red";
main.appendChild(btn);
}
// 调用函数创建链接
createa("http://www.imooc.com","慕课网");
</script>
</body>
</html>这代码哪里错了呢?谢谢?
另外,用setAttribute怎么设置颜色属性啊?
关键是没在页面上显示你写的这个链接, btn.setAttribute("value",text);这块不能这么写,应该用innerHTML来做。你是要设置背景色?还是设置字体颜色?
颜色设置的话要写 btn.setAttribute("style","color:red");
JavaScript进阶篇
469062 学习 · 22582 问题
相似问题