我正在尝试根据复选框标签文本将复选框列表动态标记为“已选中”。
这是一些标记示例:
<li class="checkboxlist-item">
<input type="checkbox" id="Categories_24" value="eb9d6610-914b-4e14-99d1-a22200cd5369" name="Categories.SelectedIds" />
<label for="Categories_24">Properties & Moving</label>
</li>
因此,如果标签文本是“Properties & Moving”,我想将此处的输入元素标记为“已选中”
非常感谢您的帮助 - 谢谢!
最佳答案
我会使用 .filter ,因此您可以确定准确的字符串:
$(".checkboxlist-item label").filter(function() {
return $(this).text() === "Properties & Moving";
}).siblings(":checkbox").prop("checked", true);
关于javascript - jQuery:添加基于单独标签元素的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22810736/