如何使用innerHTML用段落填充一些文本?我需要在文本框中输入一个数字,然后重复一些文本与输入到文本框中的数字一样多的次数。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ex10.js</title>
</head>
<body>
<input type="text" id="input-type" onKeyUp="myFunction()">
<p id="sample-text">Here is some text</p>
<script>
function myFunction() {
let count = document.getElementById("input-type").value;
document.getElementById("sample-text").innerHTML = count;
if (isNaN(count)) {
document.getElementById("sample-text").innerHTML = "Error. Not a number";
}
else {
for(int i = 0; i < count; i++) {
document.getElementById("sample-text").innerHTML = "This is some text";
}
}
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)