I'm trying to create a simple javascript to create a textbox however when running the code the console log in chromium gives the following error: Uncaught ReferenceError: documet is not defined
我正在尝试创建一个简单的javascript来创建一个文本框但是当运行代码时,控制台登录chrome会出现以下错误:未捕获的ReferenceError:未定义documet
This is my html5 doc:
这是我的html5文档:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="UTF-8">
<meta name="description" content="">
<link rel="stylesheet" href="css/style.css">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<header>
</header>
<main>
<input type="button" name="textbox" value="Create a textbox" onClick="create_textbox();" />
<div id="content" class="content"><p>test</p></div>
</main>
<footer></footer>
</body>
</html>
This is my javascript:
这是我的javascript:
function create_textbox() {
var content = document.getElementById("content").innerHTML;
var div = document.getElementById("content");
document.getElementById("content").innerHTML=content+"<p>test</p>";
var input = documet.createElement("input");
input.type = "text";
var i = 0;
input.name = String("textbox"+i++);
div.appendChild(input);
}
1 个解决方案
#1
Access it using document
, not documet
(note the n
before the t
), in this line:
使用文档访问它,而不是文档(注意t之前的n),在这一行:
var input = documet.createElement("input");
// Add n here ----^
#1
Access it using document
, not documet
(note the n
before the t
), in this line:
使用文档访问它,而不是文档(注意t之前的n),在这一行:
var input = documet.createElement("input");
// Add n here ----^