【问题标题】:Add the total checkbox checked in the textbox添加在文本框中选中的总复选框
【发布时间】: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>
}

上面的脚本只运行检查每一行的所有复选框。

我想创建一个函数来计算已选中的复选框的数量,结果在文本框中(总选中)。 我试过了,但没有用。请帮忙:)

【问题讨论】:

标签: javascript asp.net-mvc


【解决方案1】:

触发功能开启时可以使用。

var checkedCount = $("[type='checkbox']:checked").lenght

【讨论】:

    【解决方案2】:

    在你的 document.ready 函数上使用它..

    var checkednum = $('input:checkbox:checked').length;
    alert(checkednum)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-20
      • 1970-01-01
      • 2011-08-28
      • 1970-01-01
      • 1970-01-01
      • 2022-06-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多