【发布时间】:2014-05-05 05:17:26
【问题描述】:
我正在寻找一个 div 的当前值,并在另一个 div 的切换上添加或减去该当前值。
流程看起来像这样:
- 获取当前值
- 点击后添加“10”
- 第二次点击时减去“10”
- 返回新值
到目前为止,我已经想出了这个。问题是它通过前两次单击从加法到减法,但在第三次单击时它停留在减法。
$("#clickThis").click(function(e){
e.stopPropagation();
var costVal = parseInt($("#cost").text(),10);
var costNewVal = costVal + 22;
var costOldVal = costNewVal - 22;
$("#cost").toggle(
function(){
$(this).text(costNewVal);
console.log("Addition");
},
function(){
$(this).text(costOldVal);
console.log("Subtraction");
}
);
});
【问题讨论】:
标签: jquery html math user-interface