如何定义计算器?
Uncaught ReferenceError: calculator is not defined
at HTMLButtonElement.onclick
当我尝试在网络浏览器中运行代码时,我从未得到答案。我可以在框中写,然后单击按钮,但我从来没有得到结果。
var Calculator = function(inp1,inp2,reslt) {
this.valinp1 = inp1;
this.valinp2 = inp2;
this.result = reslt;
if (!Calculator.prototype.sum) {
calculator.prototype.sum = function() {
var value1 = Number(this.valinp1.value),
value2 = Number(this.valinp2.value);
this.result.innerHTML =
(!/[0-9]/.test(String(value1)) || !/[0-9]/.test(String(value1)))
: (value1 + value2);
};

<input id="v1" type="text" style="width:5em;"/>
<button onclick="calculator.sum();">+</button>
<button onclick="calculator.multiply();">*</button>
<button onclick="calculator.div();">/</button>
<button onclick="calculator.mod();">%</button>
<input id="v2" type="text" style="width:5em;"/>
<span id="result"> </span>
&#13;