javascript - 如何修复未捕获的类型错误:无法读取 null 的属性“值”
问题描述
我正在尝试修复错误,但它仍然说 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>
解决方案
value
应该是小写。这就是为什么当您获取 nameField 节点值的文档时会出现未定义的原因。对于名称字段。
let nameField = document.getElementById("nameField").value;
推荐阅读
- docker - 带有 RQ 工作者的 Flask 应用程序:仅在工作者端执行导入
- python-3.5 - 使用 PySnmp 进行异步 snmp 表遍历
- laravel - Laravel websockets + Laravel Echo 不听我的事件
- blazor - Blazor - 全局对象 - 使用 SessionStorage?
- python - 无法将 Power Apps 中的 Base64 字符串正确解码为音频文件
- http - 关闭连接后写入响应错误
- excel - 将整张工作表读取到 VBA 的最佳解决方案是什么?
- java - 为什么 kotlin 中的属性覆盖使主构造函数属性为零
- python - Pandas:将多个日期添加到单个列
- r - rbind(deparse.level, ...) 中的错误:参数的列数与 R 不匹配