![](/img/trans.png)
[英]Javascript error log says function not defined when I have defined it in a separate file and even the same file
[英]Hey i have a problem when I press the button I have an error in the console log which says my function is not defined
因此,當您單擊按鈕時,控制台會顯示:“project3.html:48 Uncaught ReferenceError: findnembers is not defined at HTMLButtonElement.onclick (project3.ZFC35FDC70D5FC69D2539883A822C)” 太感謝了
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>project3</title>
</head>
<body dir="ltr">
<button id="click here to calculate" onclick="findnembers();" type=button>click here to calculate </button>
<div id='rslt' style='text-align: center;font-size: 1em; font-weight: bolder;' value=""></div>
<script>
function sumdigits(num) {
sum = 0;
while (num) {
sum += num % 10;
num = Math.floor(num / 10);
}
return sum;
}
function findnembers() {
var counter = 0;
var list='<ol>';
for (let i = 0; i < 9999; i++) {
var ezer = sumdigits(i);
if (ezer === 9) {
list+= "<li>" + i + "</li>";
counter++;
}
list += "</ol>";
}
var print=list+
<p style='text-align: center;font-size: 1em; font-weight: bolder;'>"The sum of digits of those number is 9, and they are in the range 0 to 9999 inclusive and their quantity is "{counter}</p>;
document.getElementById("rslt").innerHTML=print;
}
</script>
</body>
</html>```
正如@kinglish所說的那樣。 應該是這樣的
var print=`${list}<p style='text-align: center;font-size: 1em; font-weight: bolder;'>"The sum of digits of those number is 9, and they are in the range 0 to 9999 inclusive and their quantity is "${counter}</p>`;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.