![](/img/trans.png)
[英]I am getting:Uncaught TypeError: Cannot set property 'textContent' of null
[英]i am getting an Uncaught TypeError: Cannot set property 'onclick' of null
// insert value using add buttons
btnadd.onclick= (event)=>{
let flag = bulkcreate(db.products, {
custname: custname.value,
items: items.value,
name: proname.value,
seller: seller.value,
price: price.value
});
}
当我写这段代码然后在控制台给出一个错误是 main.js:25 Uncaught TypeError: Cannot set property 'onclick of null 为什么这个错误来了请帮我找到一个解决方案
这是因为您需要创建按钮,获取对它的引用,然后将其传递给您的代码
在你的 html
<button type="button" id="btn_add">Add</button>
然后是你的 JS,考虑在页面加载事件中使用它:
var btnadd = document.getElementById("btn_add");
btnadd.onclick= (event)=>{
let flag = bulkcreate(db.products, {
custname: custname.value,
items: items.value,
name: proname.value,
seller: seller.value,
price: price.value
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.