[英]JQuery Calculator: Calculate Input, Clear After
http://jsbin.com/UYusECo/1/ http://jsbin.com/UYusECo/1/
http://jsbin.com/UYusECo/1/edit http://jsbin.com/UYusECo/1/edit
All the functions on the calculator work fine, but after I hit equal for say 6+6= and then my result shows to be 12. When I press 2 or any other number I want to clear the input of 12 or whatever the last calculation was and start a new calculation. 计算器上的所有功能都可以正常工作,但是在我说等于6 + 6 =之后,我的结果显示为12。当我按2或任何其他数字时,我想清除输入12或进行任何最后一次计算并开始新的计算。 Can anyone help me on this? 谁可以帮我这个事?
Looking at you code, it will be a bit messy but when hitting equals set a variable to true 看着你的代码,会有些混乱,但是当点击等于时,将变量设置为true
newCalc = true;
When catching the input if (newCalc) {$("#clear).trigger (); newCalc = false}
捕获输入时, if (newCalc) {$("#clear).trigger (); newCalc = false}
Here's an easier way to do it, where you don't have to edit every button. 这是一种更简单的方法,您无需编辑每个按钮。 Just use this as the handler for your =
key: 只需将其用作=
键的处理程序即可:
comp.click(function () {
Input.val(eval(Input.val()));
$('input:button').one('click', function newOp(e) {
if (/\d/.test(this.value)){
Input.val(this.value);
}
$('input:button').off('click', newOp);
});
});
Not the best way to do it, certainly, but it works. 当然,这不是最好的方法,但是它可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.