Добавить общий флажок в текстовом поле - PullRequest
0 голосов
/ 21 января 2019

У меня есть вид, как показано ниже

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

Приведенный выше скрипт запускается только для проверки всех флажков в каждой строке.

и я хочу создать функцию для подсчета количества флажков, которые были отмечены, результаты находятся в текстовом поле (Всего проверено). Я пытался, но это не сработало. Пожалуйста, помогите:)

Ответы [ 2 ]

0 голосов
/ 21 января 2019

используйте это в вашей функции document.ready ..

var checkednum = $('input:checkbox:checked').length;
alert(checkednum)
0 голосов
/ 21 января 2019

Вы можете использовать это при включении функции запуска.

var checkedCount = $("[type='checkbox']:checked").lenght
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...