【发布时间】:2021-02-21 18:01:47
【问题描述】:
JS新手,有人能指出我在下面犯了什么错误吗?按钮不起作用。
<!DOCTYPE html>
<html>
<body>
<button onclick ="insertFunction()"> click me! </button>
<div id ="containerDiv">
</div>
<script>
var textArray = [
{name: "Harry"}, {place: "London"} ]
function insertFunction() {
textArray.forEach(function(value,index){
var insertText = '<p>Hello' +value.name+'</p>';
document.getElementBydID("containerDiv").innerHTML+=insertText;
});
}
</script>
</body>
</html>
【问题讨论】:
-
你有一个错字
getElementBydID应该是getElementById -
“不工作”不是诊断性的。请始终提供详细信息。
标签: javascript html button bootstrap-4