【发布时间】:2014-06-29 21:34:45
【问题描述】:
在下面的代码中有复选框,每次选中复选框时都会添加该复选框值(有效)。但是当它未被选中时,它应该删除该复选框值。但相反,它只是将值添加两次。如何添加和删除未选中的值?
这是代码示例
//Looks for every checkbox
$('#index '+ selected +' #cbFieldSet .icheck').each( function(i, name){
console.log("#"+ $(name).attr("id"));
if($('input[name='+$(name).attr('name')+']').attr('checked', false)){
//checks what checkbox has been check. Gets that checkbox id
$('#index '+ selected +' #cbFieldSet #'+ $(name).attr("id")).click( function(){
// $("#cb-"+playerStart).click(function(){
//console.log(i);
console.log('yes');
//add to popup box paragragh
$('#popupDialog #info').append($(name).val());
});
}else if($('input[name='+$(name).attr('name')+']').attr('checked', true)){
//checks what checkbox has been check. Gets that checkbox id
$('#index '+ selected +' #cbFieldSet #'+ $(name).attr("id")).change( function(){
// $("#cb-"+playerStart).click(function(){
//console.log(i);
console.log('yes');
//add to popup box paragragh
$('#popupDialog #info').remove( ":contains("+ $(name).val() +")" );
});
}
});
【问题讨论】:
标签: javascript jquery jquery-mobile