[英]Adding <li> to an existing <ul>
I have a MultiSelectList
in View. 我在视图中有一个MultiSelectList
。
@Html.ListBox("AreaList",new MultiSelectList(new List<State>()),
new { @class = "chosen-select", data_placeholder = "انتخاب منطقه...", style = "width: 90%;", tabindex = "4" }
)}
<div id="AreaList_chosen" title="" style="width: 994px;" class="chosen-container chosen-container-multi chosen-with-drop chosen-container-active">
<ul class="chosen-choices">
<li class="search-field">
<input tabindex="4" value="انتخاب منطقه..." class="default" autocomplete="off" style="width: 89px;" type="text">
</li>
</ul>
<div class="chosen-drop">
<ul class="chosen-results"></ul>
</div>
</div>
I want to add li
to ul.chosen-results
in jQuery. 我想在ul.chosen-results
中添加li
。 I use this code but it doesn't append items. 我使用此代码,但未附加项目。
var li = $('<li></li>');
li.html('Test!');
$("#AreaList_chosen > div.chosen-drop ul").append(li);
$(".chosen-results").append(li);
You need to add an option to the select that the chosen
plugin is applied to 您需要为chosen
插件添加一个选择项
$('#AreaList').append($('<option></option>').text('Test!').val(''));
and then trigger the updated event 然后触发更新的事件
$('#AreaList').trigger('chosen:updated');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.