dongping1689 2014-06-23 14:03
浏览 24
已采纳

多选复选框选中的问题

What i did

 1. create array of checkboxes with unique numeric ID 
 2. on click of <td>(with unique numeric ID also ) i checked-unchecked the checkbox 
 3. I used jQuery to check-uncheck logic.

Problem : When i click fresh on it will change to checked. Then i again click on it and it unchecked.Then i continue this process and it gets stucks on checked.

http://jsfiddle.net/5zQFe/

  • 写回答

2条回答 默认 最新

  • dongtun1872 2014-06-23 14:28
    关注

    Yup, I just made sure the input was declared rather than the ID of the TD:

    $(document).ready(function () {
        $('.tdbox').click(function () {
            var tdID = $(this).attr('id');
            if ($(this).attr('id') == -1) {
                return false;
            }
            var inp = $(this).find("input[id=" + tdID + "]");
    
            if (inp.is(':checked')) {
                $(inp).prop("checked", false);
                $(this).css('background-color', "");
            } else {
                $(inp).prop("checked", true);
                $(this).css('background-color', "yellow");
            }
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • douce1368 2014-06-23 14:25
    关注

    Try:

    .prop("checked", false);
    

    and

    .prop("checked", 'checked');
    

    in place of .attr(...)

    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Tpad api账户 api口令
  • ¥30 ppt进度条制作,vba语言
  • ¥15 stc12c5a60s2单片机测光敏ADC
  • ¥15 生信simpleaffy包下载
  • ¥15 请教一下simulink中S函数相关问题
  • ¥15 在二层网络中,掩码存在包含关系即可通信
  • ¥15 端口转发器解析失败不知道电脑设置了啥
  • ¥15 Latex算法流程图行号自定义
  • ¥15 关于#python#的问题:我在自己的电脑上运行起来总是报错,希望能给我一个详细的教程,(开发工具-github)
  • ¥40 基于51单片机实现球赛计分器功能