我想在检查后取出两个不同的值,并取消选中jquery中的复选框

时间:2015-11-27 14:31:37

标签: jquery

$('#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));

}

1 个答案:

答案 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));
}