我正在制作一个简单的计算器,但我的功能不起作用:
HTML:
<div id="mathLine">0</div>
<div id="score">none</div>
<button id="clear" class = "num" ocnlick="clear(0)">C</button>
<button id="exp" class = "num" >exp</button>
<button id="sqrt" class = "num">sqrt</button>
<button id="buttonide" class = "num">/</button>
<button id="seven7" class = "num" onclick="numerical(7)">7</button>
<button id="eight8" class = "num" onclick="numerical(8)">8</button>
<button id="nine9" class = "num" onclick="numerical(9)">9</button>
<button id="multiply" class = "num" onclick="numerical('X')">X</button>
JS
var equation = [];
function numerical(number){
equation.push(number);
document.getElementById('mathLine').innerHTML = equation;
console.log(equation);
};
function clear (j) {
for (j; j < (equation.length+2); j++){
equation.pop();
}
console.log(equation);
document.getElementById('mathLine').innerHTML = "0";
};
更多信息:
- js 文件在 html 中正确实现;
- 第一个函数(数字)运行良好;
- 当我在单独的 html 文件中尝试时列出项目,我将 html 和 js 放入标签中,一切正常
所以我不知道出了什么问题...也许我看得太久了,没有看到明显的东西?
最佳答案
你有一个错字。尝试将“ocnlick”更改为“onclick”。
关于javascript - JavaScript : not working . 内部HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38752139/