Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
附加选项后。是否可以立即选择一个选项..例如,在一个语句中附加后立即选择选项 3
<Select class="yt"></select> var select = "<option val='1'>1</option><option val='2'>2</option><option val='3'>3</option>" $(".yt").append(select)
使用 .val()
演示
$(".yt").append(select).val('3');
OP评论后更新
var select = "<option val='1'>1</option><option val='2'>2</option><option name='sel' val='3'>3</option>" $(".yt").append(select).val($('.yt option[name="sel"]').attr('val'));
试试这个
$('.yt').val('3');
更新
你可以制作自己的功能
$.fn.select = function () { this.closest('select').val(this.val()); }
然后像这样使用它
$('.yt option[name="test"]').select();