$('#exp2').click(function(){
if ($(this).attr('checked',true)){
var getamt2 = $(this).val();
var getamt4 = $('#amount_span').html(); alert(getamt4);
/*var tot = getamt0+getamt1;
$('#amount_span').html();*/
$('#amount_span').html( parseInt(getamt4) + parseInt(getamt2));
}
else{
var getamt2 = $(this).val();
var getamt4 = $('#amount_span').html(); alert('else');
/*var tot = getamt0+getamt1;
$('#amount_span').html();*/
$('#amount_span').html( parseInt(getamt4) - parseInt(getamt2));
}
答案 0 :(得分:1)
试试这个:
if($(this).prop('checked')){
your code..
}
和
if($(this).is(':checked')){
your code..
}
像这样:
$('#exp2').click(function(){
if ($(this).prop('checked')){ // <--- here is the edit
var getamt2 = $(this).val();
var getamt4 = $('#amount_span').html(); alert(getamt4);
/*var tot = getamt0+getamt1;
$('#amount_span').html();*/
$('#amount_span').html( parseInt(getamt4) + parseInt(getamt2));
}
else{
var getamt2 = $(this).val();
var getamt4 = $('#amount_span').html(); alert('else');
/*var tot = getamt0+getamt1;
$('#amount_span').html();*/
$('#amount_span').html( parseInt(getamt4) - parseInt(getamt2));
}