!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("input");
btn.setAttribute("type", "button");
btn.setAttribute("name", "q");
btn.setAttribute("value", text);
btn.setAttribute("onclick", "javascript:window.open(url);");
main.appendChild(btn);
}
// 调用函数创建链接
createa("http://www.imooc.com","慕课网");
</script>
</body>
</html>
你把那个网址的协议部分http改成https就可以了
首先<!DOCTYPE HTML>少了"<";
其次,用javascript:(冒号)...创建js语句,在这里相当于createa()函数外的一条js语句,怎么能够调用createa()的形参呢?(在<body>内,但不在<script>内)所以,建议用<a>