html
<div class="col-sm-7">
<select class="col-xs-10" id="accessoryId"></select>
</div>
js
$('#accessoryId option:contains(' + *** + ')').each(function() {
if ($(this).text() == ***) {
$(this).attr('selected', true);
}
});
本文介绍了一种使用JavaScript来遍历并高亮显示HTML下拉菜单中包含特定字符串的选项的方法。通过对选择器的精确控制,可以实现对指定文本的自动选中。
html
<div class="col-sm-7">
<select class="col-xs-10" id="accessoryId"></select>
</div>
js
$('#accessoryId option:contains(' + *** + ')').each(function() {
if ($(this).text() == ***) {
$(this).attr('selected', true);
}
});

被折叠的 条评论
为什么被折叠?