gpt4 book ai didi

javascript - 无法设置 null 的属性 innerHTML(javascript)

转载 作者:行者123 更新时间:2023-11-30 15:36:12 25 4
gpt4 key购买 nike

<分区>

我知道有很多主题,但没有一个能回答我的问题。我必须在窗口中按字典顺序打印最小和最大的属性。但是我得到了错误 Cannot set property of innerHTML of null at solve。这是我的 html:

<!DOCTYPE html>
<html lang="en">

<head>
<title>Loops Homework</title>
<meta charset="UTF-8">

</head>

<body>
<span>Problem 1</span>
<button onclick="solve()">Print</button>
<div id="answer1">Answer will appear here</div>
<script src="LexicographicallyProp.js" type="text/javascript"></script>
</body>

</html>

以及以下 javascript 文件:

function solve() {
let smallest = 'zzz',
largest = '',
prop,
div1 = document.getElementById('#answer1');

for (prop in document) {
if (prop < smallest) {
smallest = prop;
}

if (prop > largest) {
largest = prop;
}
}
div1.innerHTML = 'Smallest property in DOCUMENT: ' + smallest + ' ; Largest prop in DOCUMENT: ' + largest;

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com