Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery:按每个表行检查无线电不工作_Javascript_Jquery - Fatal编程技术网

Javascript Jquery:按每个表行检查无线电不工作

Javascript Jquery:按每个表行检查无线电不工作,javascript,jquery,Javascript,Jquery,我想循环表中的每一行并检查收音机。如果默认情况下没有选中,我们将检查它的值=Local,如果默认情况下已经选中,只需保留它 我的代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>JS Bin</title> <

我想循环表中的每一行并检查收音机。如果默认情况下没有选中,我们将检查它的值=Local,如果默认情况下已经选中,只需保留它

我的代码如下:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script>
    $( document ).ready(function() {
    $('.tableA tr').each(function (index) {
      //processing this row         
      //how to process each cell(table td) where there is checkbox  
      var countChecked = 0;
      console.log("Row: "+index);
        if(!$(this).find('input[type="radio"]').is(":checked")){
          console.log("None Checked");
          countChecked = 1;
        } else {
          var radioValue = $(this).find('input[type="radio"]:checked').val();
          console.log("This row has checked: "+radioValue);
        }

        if (countChecked>0){
          $(this).find(':radio[name=radioName][value=Local]').attr('checked', true);        
        }
      });      
    });
  </script>
</head>
<body>
<table class="tableA" border='1'>
<tr>
  <td>
<input type="radio" name="radioName" class="myRadio" value="1" /> 1 <br />
<input type="radio" name="radioName" class="myRadio" value="2" /> 2 <br />
<input type="radio" name="radioName" class="myRadio" value="3" /> 3 <br />
<input type="radio" name="radioName" class="myRadio" value="Local" /> Local <br />
  </td>
</tr>
<tr>
  <td>
<input type="radio" name="radioName" class="myRadio" value="1" /> 1 <br />
<input type="radio" name="radioName" class="myRadio" value="2" checked /> 2 <br />
<input type="radio" name="radioName" class="myRadio" value="3" /> 3 <br />
<input type="radio" name="radioName" class="myRadio" value="Local" /> Local <br />
  </td>
</tr>
<tr>
  <td>
<input type="radio" name="radioName" class="myRadio" value="1" /> 1 <br />
<input type="radio" name="radioName" class="myRadio" value="2" /> 2 <br />
<input type="radio" name="radioName" class="myRadio" value="3" /> 3 <br />
<input type="radio" name="radioName" class="myRadio" value="Local" /> Local <br />
  </td>
</tr>  
</table>


</body>
</html>

控制台将正确显示。有什么想法吗?

尝试使用
prop
而不是
attr
检查属性

$(this).find(':radio[name=radioName][value=Local]').prop('checked', true); 

尝试对选中的属性使用
prop
而不是
attr

$(this).find(':radio[name=radioName][value=Local]').prop('checked', true); 

真正的问题是,所有的广播节目都有相同的名字,所以它们实际上是一个大的广播组。这意味着只能选择12个选项中的一个

确保3个组中的每个组都有唯一的名称,然后从选择器过滤器中删除
name=radioName


JS-Bin
$(文档).ready(函数(){
$('.tableA tr')。每个(函数(索引){
//正在处理此行
//如何处理有复选框的每个单元格(表td)
var countChecked=0;
console.log(“行:”+索引);
如果(!$(this).find('input[type=“radio”]”)是(“:checked”)){
控制台日志(“未选中”);
countChecked=1;
}否则{
var radioValue=$(this).find('input[type=“radio”]:checked').val();
console.log(“此行已选中:”+radioValue);
}
如果(countChecked>0){
$(this).find(':radio[value=Local]').attr('checked',true);
}
});      
});
1
2
3
本地
1
2
3
本地
1
2
3
本地

真正的问题是,所有广播节目都有相同的名称,因此它们实际上是一个大型广播组。这意味着只能选择12个选项中的一个

确保3个组中的每个组都有唯一的名称,然后从选择器过滤器中删除
name=radioName


JS-Bin
$(文档).ready(函数(){
$('.tableA tr')。每个(函数(索引){
//正在处理此行
//如何处理有复选框的每个单元格(表td)
var countChecked=0;
console.log(“行:”+索引);
如果(!$(this).find('input[type=“radio”]”)是(“:checked”)){
控制台日志(“未选中”);
countChecked=1;
}否则{
var radioValue=$(this).find('input[type=“radio”]:checked').val();
console.log(“此行已选中:”+radioValue);
}
如果(countChecked>0){
$(this).find(':radio[value=Local]').attr('checked',true);
}
});      
});
1
2
3
本地
1
2
3
本地
1
2
3
本地

像这样更改代码。使用
prop
而不是
attr

 $(this).find('input[value=Local]').prop('checked', true);
也要做下面的事情

  • 设置单选按钮的
  • 不要对所有单选按钮使用相同的名称。因为radion按钮是按名称分组的。所以请对每个组使用单独的名称
  • $(文档).ready(函数(){
    $('.tableA tr')。每个(函数(索引){
    var countChecked=0;
    如果(!$(this).find('input[type=“radio”]”)是(“:checked”)){
    countChecked=1;
    }否则{
    var radioValue=$(this).find('input[type=“radio”]:checked').val();
    }
    如果(countChecked>0){
    $(this.find('input[value=Local]')).prop('checked',true);
    }
    });
    });
    
    
    1
    2
    3
    本地
    1
    2
    3
    本地
    1
    2
    3
    本地

    像这样更改代码。使用
    prop
    而不是
    attr

     $(this).find('input[value=Local]').prop('checked', true);
    
    也要做下面的事情

  • 设置单选按钮的
  • 不要对所有单选按钮使用相同的名称。因为radion按钮是按名称分组的。所以请对每个组使用单独的名称
  • $(文档).ready(函数(){
    $('.tableA tr')。每个(函数(索引){
    var countChecked=0;
    如果(!$(this).find('input[type=“radio”]”)是(“:checked”)){
    countChecked=1;
    }否则{
    var radioValue=$(this).find('input[type=“radio”]:checked').val();
    }
    如果(countChecked>0){
    $(this.find('input[value=Local]')).prop('checked',true);
    }
    });
    });
    
    
    1
    2
    3
    本地
    1
    2
    3
    本地
    1
    2
    3
    本地
    试试这个

    $("input[name=radioName][value='local']").prop("checked",true);
    
    试试这个

    $("input[name=radioName][value='local']").prop("checked",true);
    
    根据您的描述查找正在工作/已修改。如果需要任何修改,请发表评论

    所做的修改:

    1.为每个表格行(tr)上的单选按钮使用唯一名称

    2.在代码行下方修改

    if (countChecked>0){
              $(this).find(':radio[value=Local]').prop('checked', 'checked');        
            }
    
    根据您的描述查找正在工作/已修改。如果需要任何修改,请发表评论

    所做的修改:

    1.为每个表格行(tr)上的单选按钮使用唯一名称

    2.在代码行下方修改

    if (countChecked>0){
              $(this).find(':radio[value=Local]').prop('checked', 'checked');        
            }
    

    每个
    radio
    名称都是
    radioName
    。是吗?是的,那是正确的。Young Kyun Jin是正确的电台名称应该是
    radioName1
    radioName2
    radioName3
    对于每个
    tr
    电台
    名称是
    radioName
    。正确吗?是的,正确。Young Kyun Jin是正确的电台名称应该是
    radioName1
    radioName2
    radioName3
    对于每个
    tr
    不工作的问题,在jsbin链接上尝试上面的问题不工作,在jsbin链接上尝试上面的问题