[英]radio button in a table checked and unchecked
我在表格中有一個單選按鈕,我想根據名稱實現單選按鈕的所有功能。 這是我的代碼:
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>
我無法選擇名為bundleAcceptAll的所有單選按鈕。 它基本上是一個列表,其中每一行都有一個單選按鈕。 我希望選擇列表中的所有單選按鈕。 只選擇一個按鈕
AFAIK如果您選擇單選按鈕並使用相同的名稱,它將被視為僅選擇一個項目的組。 也許你可以把它改成復選框。
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>
如果是列表,則可以遍歷列表並選中或取消選中
$("input[type=radio][name='" + name + "']").each(function() {
//code here
});
如上所述,選中多個項目不是單選按鈕功能,而是復選框。 但你可以設置復選框樣式,使它們看起來像radiobuttons。 請參閱示例: 如何使用自定義css創建圓形復選框?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.