简体   繁体   English

选中并取消选中表格中的单选按钮

[英]radio button in a table checked and unchecked

I have a radio button in table and I want to implement select all functionality for radio button based on name. 我在表格中有一个单选按钮,我想根据名称实现单选按钮的所有功能。 This is my code: 这是我的代码:

var checked = false;

$scope.acceptOrRejectAllOrders = function(selectedVal) {
  if (selectedVal == 'Accept all') {
    jQuery("#bundleAcceptAll").attr('checked', 'checked');

    // $("#bundleAcceptAll").prop("checked", true);
    //$("#bundleAcceptAll").attr('checked', 'checked');

    var aa = document.getElementsByName("bundleAcceptAll");
    for (var i = 0; i < aa.length; i++) {
      document.getElementsByName(bundleAcceptAll).checked = true;
    }

    //$scope.quoteRequest.quotationRequestItems[0].quotes.length
  } else {
  }
};
<div style="border:1px #f5f4f4 solid;background: #f9f9f9;" ng-repeat="(key,quoteAndOrder) in getQuotesAndOrders()">
  <div style="background: #fff;">
    <table border="0" style="width: 100%;" class="table table-striped">
      <thead>
        <tr style="background: #ff7900;color: #fff;">
          <th>Quote ID</th>
          <th>{{key}}</th>
        </tr>
        <tr>
          <th>Accept or Reject Orders:</th>
          <th>
            <span style="float: left;background: #f9f9f9;">
              <input type="radio" name ="bundleAcceptAll" ng-change="" class="radioSignatory" value="Approve Order" ng-disabled=""> 
              <p class="labelRadioSignatory">Approve Order</p>
              <input type="radio" name ="bundleRejectAll"  ng-change="" class="radioSignatory" value="Reject Order" ng-disabled=""> 
              <p class="labelRadioSignatory">Reject Order</p>
            </span>
          </th>
        </tr>
      </thead>
      <tr ng-repeat="odr in quoteAndOrder">
        <td> {{odr.id}} </td>
        <td>{{odr.status}}</td>
      </tr>
    </table>
    <hr>
  </div>
</div>

I am not able to select all radio buttons with name bundleAcceptAll. 我无法选择名为bundleAcceptAll的所有单选按钮。 It is basically a list in which each row will have a radio button. 它基本上是一个列表,其中每一行都有一个单选按钮。 I want all radio buttons in the list to be selected. 我希望选择列表中的所有单选按钮。 Only one button gets selected 只选择一个按钮

AFAIK if you choose radio button and use the same name it will treated as group that will only one item selected. AFAIK如果您选择单选按钮并使用相同的名称,它将被视为仅选择一个项目的组。 Perhaps you could just change it into checkbox. 也许你可以把它改成复选框。

 function oncheckClick() { $('input[name=chkBox]').prop('checked',true) } function onUnCheckClick() { $('input[name=chkBox]').prop('checked',false) } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="radio" name="chkBox"> <button id="check" onclick="oncheckClick()" value="Check">Check</button> <button id="check" onclick="onUnCheckClick()" value="UnCheck">UnCheck</button> 

if it is list, you can loop through the list and check or uncheck 如果是列表,则可以遍历列表并选中或取消选中

$("input[type=radio][name='" + name + "']").each(function() {
//code here

}); });

As was mentioned above, it's not radio button functionality to have multiple items checked, it's checkboxes. 如上所述,选中多个项目不是单选按钮功能,而是复选框。 But you can style checkboxes so they would look like radiobuttons. 但你可以设置复选框样式,使它们看起来像radiobuttons。 See for example: How to make a checkbox in circle shape with custom css? 请参阅示例: 如何使用自定义css创建圆形复选框?

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

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