[英]jQuery adding option to select box with selected arbitrate
I want to add a option to a existing select element. 我想向现有的选择元素添加一个选项。
Below code works without any issue 下面的代码可以正常工作
$('#selectStory').append($('<option>', {
value: 1,
text: 'Red'
}));
Only issue is that i cant make it selected. 唯一的问题是我无法将其选中。
Can someone tell me how to do this. 有人可以告诉我该怎么做。
$('#selectStory').append($('<option>', { value: 1, text: 'Red', selected: 'selected' }));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select id='selectStory'> <option></option> </select>
Add selected
添加selected
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.