jQuery包含选择器不适用于特定的innerHTML

时间:2019-03-25 13:14:49

标签: javascript jquery selector innerhtml contains

我正在使用以下代码显示复选框列表:

{% for keyword in keywords %}
    <div class="col m4 s12">
        <p class="range-field">
            <input type="checkbox" id="{{loop.index}}" name="{{keyword.title}}" class="filled-in"/>
            <label for="{{loop.index}}">{{keyword.title}}</label>
            <input type="range" min="0" max="100"/>
        </p>
   </div>
{% endfor %}

在对表格进行汇总后,服务器会获取所选复选框的列表,并将其发送回去,以便我可以将其再次查看

{% for keyword in selected_keywords %}
    <script>
        $("label:contains('{{keyword.keyword}}')").prev().attr('checked',true);
    </script
{% endfor %}

我使用contains作为选择器,但不适用于innerHTML。例如,如果我有Java和javascript,并且仅在提交javascript之后也检查了java,那么我只会检查java。我搜索了其他相关问题,其中大多数似乎都使用了contains,但不适用于特定的innerHTML。

0 个答案:

没有答案
相关问题