作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 JavaScript 中调用一个函数,如图所示
var count = 0;
function resetGroupsSelector(groupId){
//alert(groupId);
console.log("search_report_form:"+groupId)
//alert("search_report_form:"+groupId)
var id = "search_report_form:"+groupId;
document.getElementById("id").innerHTML("HI");
}
但是我得到了
Uncaught TypeError: Cannot call method 'innerHTML' of null
错误。我不知道出了什么问题。
最佳答案
简单语法错误:
document.getElementById("id").innerHTML("HI");
应该改成这样:
document.getElementById(id).innerHTML = "HI";
^^ ^^^^^^^
不要忘记从 id
中删除引号,因为它是一个变量,所以您要确保传递的是变量而不是 < em>文字字符串 "id"
关于javascript - 未捕获的类型错误 : Cannot call method 'innerHTML' of null even when I place my script code inside <body> tag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34035058/
我是一名优秀的程序员,十分优秀!