簡體   English   中英

Select / 在 Thymeleaf 中使用 jQuery 取消選擇所有復選框

[英]Select / Deselect All Checkboxes using jQuery in Thymeleaf

我正在嘗試添加選擇和取消選擇所有字段的 function。 我現在擁有的對我不起作用,我不知道為什么? 有誰知道為什么?

.....
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://igoradamenko.github.io/awsm.css/css/awsm.min.css">
    <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
    <title>Report</title>
    <script>
        $("#selectAll").click(function() {
            $("input[type=checkbox]").prop("checked", $(this).prop("checked"));
        });
    </script>
</head>
....

 <label for='selectAll'><input id="selectAll" type="checkbox">Select All </label>
            <input checked="checked" type="checkbox">Test</label>
            <label th:each="item : ${userConfig.isEnableMap}">
                <input checked="checked" type="checkbox" th:text="${item.key}" th:field="*{isEnableMap['__${item.key}__']}"/>
            </label>

我添加了更改,現在可以使用

<script>
    $(document).ready(function () {
        $("#selectAll").change(function () {
            $("input:checkbox").prop('checked', $(this).prop("checked"));
        });
    });
</script>

你可以試試:

$("input[type=checkbox]").prop("checked",true);

暫無
暫無

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

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