【发布时间】:2021-09-30 09:59:16
【问题描述】:
我正在尝试修复错误,但它仍然说 Uncaught TypeError: Cannot read property 'Value' of null in console here is html and js
function generateCV() {
// console.log("hello");
let nameField = document.getElementById("nameField").Value;
let nameT1 =document.getElementById("nameT1");
nameT1.innerHTML=nameField;
//direct
document.getElementById('nameT2').innerHTML=nameField
}
<div>
<div class="form-group">
<label for="nameField1" >Your Name</label>
<input type="text" id="nameField" class="form-control"
placeholder="Enter here here">
</div>
<div class="container text-center mt-3">
<button onclick="generateCV()"
class="btn btn-primary btn-lg">Generate cv</button>
</div>
</div>
<div class="container">
<p id="nameT1">Robin</p>
</div>
【问题讨论】:
-
在调用
getElementById()之前,你确保DOM已经完全加载了吗? -
修复这一行 -> let nameField = document.getElementById("nameField").value;将值更改为小写。
标签: javascript html typeerror