我想设置一个select框的selected值,如果存在则设置,如果不存在则添加到select框中。
我该怎么做?
我有:
<select id="abc" name="abc">
</select>
我要:
$('#abc').val(123);
之后:
<select id="abc" name="abc">
<option value="123" selected>
</select>
最佳答案
你可以追加元素
var html = '<option value="123">123</option>';
jQuery("#abc").append(html);
关于javascript - 如果具有该值的选项不存在,则设置选择字段的选定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38432585/