【问题标题】:How to set a dynamic list of checkboxes?如何设置复选框的动态列表?
【发布时间】:2014-05-15 14:08:10
【问题描述】:

我有以下与 Oracle APEX 中的复选框组相关的 HTML 代码:

<fieldset class="checkbox_group" id="P300_CELL_TECH" tabindex="-1" disabled="disabled">
    <legend class="hideMeButHearMe">
        <div id="cell-filter">
            <div style="font-size:10px;margin-left:-11px;">Select All</div>
            <input type="checkbox" checked="" name="select-all-cell" id="select-all-cell" disabled="disabled"/>
            <div class="cb-filter-label">Cells</div>
        </div>
        <hr>
    </legend>
    <table class="checkbox_group" role="presentation" summary="">
        <tbody>
            <tr>
                <td>
                    <input type="checkbox" value="0" name="p_v42" id="P300_CELL_TECH_0">
                    <label for="P300_CELL_TECH_0">0</label>
                </td>
                <td>
                    <input type="checkbox" value="1" name="p_v42" id="P300_CELL_TECH_1">
                    <label for="P300_CELL_TECH_1">1</label>
                </td>
                <td>
                    <input type="checkbox" value="2" name="p_v42" id="P300_CELL_TECH_2">
                    <label for="P300_CELL_TECH_2">2</label>
                </td>
                <td>
                    <input type="checkbox" value="3" name="p_v42" id="P300_CELL_TECH_3">
                    <label for="P300_CELL_TECH_3">3</label>
                </td>
                <td>
                    <input type="checkbox" value="4" name="p_v42" id="P300_CELL_TECH_4">
                    <label for="P300_CELL_TECH_4">4</label>
                </td>
                <td>
                    <input type="checkbox" value="5" name="p_v42" id="P300_CELL_TECH_5">
                    <label for="P300_CELL_TECH_5">5</label>
                </td>
            </tr>
        </tbody>
    </table>
</fieldset>

使用 jQuery,我如何遍历所有这些输入复选框类型并将所有这些复选框设置为选中,而不使用 name="p_v42"(因为名称可以更改)并且不知道此字段集中的确切复选框数量可能会有所不同?

我正在寻找一个只关注每个&lt;input type="checkbox" ...&gt; 的答案。

我在同一页面上还有其他复选框,但不想针对那些,只是上面描述的那些。

顶级 id 永远是:

id="P300_CELL_TECH"

【问题讨论】:

标签: jquery checkbox oracle-apex


【解决方案1】:

尝试使用:

jQuery(":checkbox[id^='P300_CELL_TECH']").prop('checked', true)

或者

jQuery(".checkbox_group :checkbox[id^='P300_CELL_TECH']" ).prop('checked', true)

或者干脆

jQuery('.checkbox_group :checkbox" ).prop('checked', true)

【讨论】:

  • “因为:checkbox 是一个jQuery 扩展而不是CSS 规范的一部分,所以使用:checkbox 的查询不能利用本机DOM querySelectorAll() 方法提供的性能提升。为了在现代浏览器中获得更好的性能,请改用[type="checkbox"]。" -- api.jquery.com/checkbox-selector
  • @Blazemonger 同意 :)
  • @Aamir - 之前尝试接受,但由于我不得不等待 5 分钟,所以没有接受。
【解决方案2】:
$('.checkbox_group input[type=checkbox]').prop('checked', true);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-17
    • 2021-08-22
    • 2015-12-06
    • 1970-01-01
    • 1970-01-01
    • 2011-10-11
    相关资源
    最近更新 更多