0 javascript model-view-controller
我试图在我的网站上创建一个民意调查功能.如果用户在按下按钮时尚未投票,并且如果用户在按下按钮时已经投票,则向下按1,我希望计数增加1.现在它只是上升到无穷大,永远不会-1.
如果我将if(已投票)更改为if(!voteed),则会发生相反的问题,并且每次点击都会变为-1.
var voted = new Boolean(false);
$(document).ready(function () {
$("#container div button").click(function () {
if (voted) {
$(this).parent().animate({
width: '+=100px'
}, 500);
$(this).prev().html(parseInt($(this).prev().html()) + 1)
voted === true;
} else {
$(this).parent().animate({
width: '-=100px'
}, 500);
$(this).prev().html(parseInt($(this).prev().html()) - 1)
voted === false;
}
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
58 次 |
| 最近记录: |