weixin_33736832 2011-01-01 05:13 采纳率: 0%
浏览 23

jQuery重新检查复选框

I having problems with re-checking some checkboxes after and ajax call updates a table.

I have a table of what the project calls 'shares'.

I want to:

1) check for and save any checked shares to an array
2) Do my ajax call to update the table of shares
3) Re-check any there we checked before the ajax update.

My code is not working and I can't see why?

Any tips, help or advise much appreciated.

// Array to hold our checked share ids
var savedShareIDs = new Array();

// Add checked share ids into array
$("input:checkbox[name=share_ids]:checked").each(function() {  
 savedShareIDs.push($(this).val());  
});     

// Do ajax update
Dajaxice.pagination_shares('Dajax.process',{'id':1, 'page':1})

// Re-check any that were checked before ajax update
$("input:checkbox[name=share_ids]").each(function()  
{  
 if ( $.inArray( $(this).val(), savedShareIDs) > -1 ) {   
  $(this).attr('checked',true)  
 }  
});

The problem is the checkboxes are not checking.
I'm pretty sure the loop is working and the inArray check works.

Just not checking the checkboxes. Can anyone see where I'm going wrong?

Thanks.

  • 写回答

3条回答 默认 最新

  • weixin_33705053 2011-01-01 05:20
    关注

    Try to change

    $(this).attr('checked',true) 
    

    to

    $(this).attr('checked','checked')
    
    评论

报告相同问题?

悬赏问题

  • ¥30 matlab解优化问题代码
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline