简体   繁体   English

切换单选按钮仅一次(刷新)吗?

[英]Toggling of radio button only works once (refresh)?

I am trying to toggle a radio box selection included in cells table. 我正在尝试切换单元格表中包含的单选框选择。

The toggling works only once per radio button. 每个单选按钮只能进行一次切换。

After, all radio buttons are disabled but my HTML code seems to be correct; 之后,所有单选按钮都被禁用,但是我的HTML代码似乎正确; the attribute checked="checked" is present. 存在属性checked="checked"

Why is this not working? 为什么这不起作用?

Here is the jQuery I am using: 这是我正在使用的jQuery:

$('td').click(function(){
    var $elem = $(this).children('input');               
    var name = $elem.attr('name');
    $('input[name='+name+']').each(function(){
       $(this).removeAttr('checked');                  
    }).promise().done(function(){                 
       $elem.attr('checked','checked');               
    });
}); 

And the image: 和图像:

在此处输入图片说明

You need to be using prop() as currently you are actually removing the attribute using removeAttr() instead of just setting it to disabled. 您需要使用prop()因为当前实际上是使用removeAttr()删除属性,而不仅仅是将其设置为Disabled。

The following will work: 以下将起作用:

$('input[name='+name+']').each(function(){
   $(this).prop('checked', false);                  
}).promise().done(function(){                 
   $elem.prop('checked', true);               
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM