【发布时间】:2019-01-21 20:20:21
【问题描述】:
我的观点如下
@using (Html.BeginForm("SubmitSelected", "Costumer", FormMethod.Post, new { id = "form-Costumer", enctype = "multipart/form-data", name = "myform" }))
{
<input type="checkbox" id="checkall" /><span>Check All</span>
<div id="checkboxes">
<table class="table table-bordered">
<thead>
<tr>
<th>
Select //this is from the class where datatype is bool
</th>
<th>
ContactNumber
</th>
<th>
ConsumerName
</th>
</tr>
</thead>
@Html.EditorFor(model => model.transaksiSelectionViewModel.Transactions)
</table>
</div>
<div class="form-group">
@Html.Label("Total Checked")
<div class="col-sm-10">
<input type="text" id="total" class="form-control" />//the result of the number checked here
</div>
</div>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
function toggleChecked(status) {
$("#checkboxes input").each(function () {
// Set the checked status of each to match the
// checked status of the check all checkbox:
$(this).prop("checked", status);
});
}
$(document).ready(function () {
//Set the default value of the global checkbox to true:
$("#checkall").prop('checked', false);
// Attach the call to toggleChecked to the
// click event of the global checkbox:
$("#checkall").click(function () {
var status = $("#checkall").prop('checked');
toggleChecked(status);
});
});
</script>
}
上面的脚本只运行检查每一行的所有复选框。
我想创建一个函数来计算已选中的复选框的数量,结果在文本框中(总选中)。 我试过了,但没有用。请帮忙:)
【问题讨论】:
-
为了更好地理解codepen.io/Mestika/pen/aitHh