簡體   English   中英

添加在文本框中選中的總計復選框

[英]Add the total checkbox checked in the textbox

我有一個視圖如下

@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>
}

上面的腳本僅運行以檢查每行上的所有復選框。

我想創建一個函數來計算已選中的復選框的數量,結果在文本框中(Total Checked)。 我試過了,但沒有用。 請幫忙:)

當觸發功能繼續時,您可以使用它。

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

在您的 document.ready 功能上使用它。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM