我的复选框遇到了问题。如果单击按钮,我正在尝试触发一个事件,这与是否选中它的操作不同。
这是我的代码
$(document).ready(function(){
$('.pointBox').click(function(event){
var operator = $(this).find('input').attr('operator');
var pointNum = parseInt($(this).find('input').val());
var pointsFromHtml = $('#newPoints').val();
var currentPoints;
var newPoints;
if(pointsFromHtml.charAt(0) == '+'){
currentPoints = parseInt(pointsFromHtml.substring(1));
} else {
return;
}
switch(operator){
case 'addition':
if(!$(this).attr('checked')){
newPoints = currentPoints + pointNum;
}
if($(this).attr('checked')){
alert();
newPoints = currentPoints - pointNum;
}
break;
case 'subtraction':
newPoints = currentPoints - pointNum;
break;
}
$('#futurePoints').text('+' + newPoints);
$('#newPoints').attr('value', newPoints);
});
});