简体   繁体   English

未捕获的TypeError:无法在第34行中将属性'innerHTML'设置为null

[英]Uncaught TypeError: Cannot set property 'innerHTML' of null in line 34

I've already searched for my problem, but the solutions were not able to help me. 我已经搜索了我的问题,但是解决方案无法帮助我。

Here's the code: 这是代码:

<!DOCTYPE html>
<html>



<head>
  <meta charset="utf-8">
  <title>Der Einmaleins - Trainer</title>  
  <link href = "style.css" type = "text/css" rel = "stylesheet">

</head>
<body>
  <h1>Der Einmaleins - Trainer</h1> 
  <button type="button" onclick = "start();">Start</button> 
  <button type = "button" onclick = "fertig();">Fertig!</button>
  <input id = "erginput" type = "number" >
  <br>
  <label id = "rn1"></label>  
  <label id = "multiplication"><label>
  <label id = "rn2"></label>  

<script>

function start() 

{   
//var anzahl = 0
//while (anzahl < 20){

var randomnumber1 = getrn();
var randomnumber2 = getrn();
document.getElementById("rn1").innerHTML = randomnumber1;
document.getElementById("multiplication").innerHTML = "x";
document.getElementById("rn2").innerHTML = randomnumber2;
//}
}

function getrn(){
var min = 3;
var max = 10;
var randomnumber = Math.floor(Math.random() * (max - min)) + min;
return randomnumber;
}</script>
</body>

I thought that the null is because randomnumber2 oder rn2 is not defined since I saw that mistake in other codes, but here they're both defined, aren't they? 我以为空是因为因为我在其他代码中看到了这个错误,所以没有定义randomnumber2或rn2,但是在这里它们都被定义了,不是吗?

Thanks in advance! 提前致谢!

Ji W 吉文

You had invalid markup! 您的标记无效! </label> was not closed.. </label>未关闭。

 function start() { var randomnumber1 = getrn(); var randomnumber2 = getrn(); document.getElementById("rn1").innerHTML = randomnumber1; document.getElementById("multiplication").innerHTML = "x"; document.getElementById("rn2").innerHTML = randomnumber2; } function getrn() { var min = 3; var max = 10; var randomnumber = Math.floor(Math.random() * (max - min)) + min; return randomnumber; } 
 <h1>Der Einmaleins - Trainer</h1> <button type="button" onclick="start();">Start</button> <button type="button" onclick="fertig();">Fertig!</button> <input id="erginput" type="number"> <br> <label id="rn1"></label> <label id="multiplication"></label> <label id="rn2"></label> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的TypeError:无法将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null 未捕获的Typeerror:无法将属性innerHTML设置为null - Uncaught Typeerror: Cannot set property innerHTML of null 未捕获的TypeError:无法将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null 未捕获的TypeError:无法将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null 未捕获的TypeError:无法设置null的属性&#39;innerHTML&#39; - Uncaught TypeError: Cannot set property 'innerHTML' of null 未捕获的TypeError:无法在phonegap中将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null in phonegap 未捕获的TypeError:无法使用for循环将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null using a for loop 未捕获(承诺)TypeError:无法将属性&#39;innerHTML&#39;设置为null - Uncaught (in promise) TypeError: Cannot set property 'innerHTML' of null 如何修复“Uncaught TypeError:无法设置属性&#39;innerHTML&#39;为null” - How to fix “Uncaught TypeError: Cannot set property 'innerHTML' of null” 未捕获的TypeError:无法设置null错误的属性&#39;innerHTML&#39; - Uncaught TypeError: Cannot set property 'innerHTML' of null error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM