当我点击复选框时,我需要显示一张图片。现在我收到一个错误:
Uncaught TypeError: Cannot read property 'checked' of null
at (index):185
at dispatch (VM576 jquery.min.js:3)
at i (VM576 jquery.min.js:3)
你能告诉我如何解决吗?我在下面提供我的代码。
http://jsfiddle.net/xda0kL6w/1/
if (document.getElementById('checkIDGrid').checked) {
alert("I am checked for the grid");
var img = $('<img />', {
id: 'Myid',
src: 'https://thumbs.dreamstime.com/z/pixel-perfect-web-development-flat-icons-set-website-programming-process-webpage-coding-user-interface-creating-45297890.jpg',
alt: 'MyAlt'
});
img.appendTo($('<tr>'));
} else {
alert("I am not checked for the grid");
}
最佳答案
像这样:
const option = document.getElementById('checkIDGrid');
if ( option && option.checked) {
...
}
关于javascript - 错误未捕获类型错误 : Cannot read property 'checked' of null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49655243/