jQuery 删除表格中单选按钮的 Checked 属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6833021/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 21:26:30  来源:igfitidea点击:

Remove Checked attribute of a radio button in a table

jquery

提问by Reddy

Here is my code, i want to clrae the response of radio when i click on the button.

这是我的代码,当我点击按钮时,我想清除收音机的响应。

<table class='x'>
<tr><td><input type="radio"></td></tr>
<tr><td><input type="text"></td></tr>
</table>
<input type='button' id="a" value="dfrfvrgv">

Here is the jQuery code

这是jQuery代码

$('#a').click(function()
          {
              $('TABLE .x').find('input').removeAttr('checked');  
          });

But it is not working, Seems to be problem with the code. Please someone help me.

但它不起作用,似乎是代码问题。请有人帮助我。

回答by Joseph Marikle

For jquery < 3.0:

对于 jquery < 3.0:

$('#a').click(function() {
            $('TABLE.x').find('input').removeAttr('checked');  
        });

For jquery >= 3.0:

对于 jquery >= 3.0:

$('#a').click(function() {
            $('TABLE.x').find('input').prop('checked', false);  
        });

// More info about removeAttr and prop you can find here https://stackoverflow.com/questions/6169826/propchecked-false-or-removeattrchecked

No space in the selector

选择器中没有空格

What you are looking for with the space in there, are any child nodes of TABLE that have the class x. table.x looks for a table with the class of x.

您正在寻找的空间是 TABLE 的任何具有 x 类的子节点。table.x 查找类为 x 的表。

回答by Darkry

$('table.x')is the right selector

$('table.x')是正确的选择器

回答by Chris Snowden

There was a space in the selector. Try the code below:

选择器中有一个空格。试试下面的代码:

$('#a').click(function()
          {
              $('TABLE.x').find('input').removeAttr('checked');  
          });