DropDownList
代码:
<div class="col-md-4">
@Html.DropDownListFor(
model => model.EmpID,
new SelectList(Model.EmployeeList(), "Value", "Text", Model.EmpID),
new { @class = "form-control" }
)
</div>
jQuery
的 DropDownList
:
<script>
$(document).ready(function () {
$("#EmpID").change(function () {
var item = $("#EmpID option:selected").text();
alert(item)
$(".test").append(item);
$("#EmpID").remove(item);
});
});
</script>
EmployeeList
的 DropDown
:
public List<SelectListItem> EmployeeList()
{
List<SelectListItem> ProjectList = mp.EmployeeMasters.Select(o => new SelectListItem()
{
Text = o.Firstname +" "+ o.Lastname,
Value = o.EmpID
}).ToList();
return ProjectList;
}
每当我选择dropdown
值并附加此值并从DrodownList
删除,但这不适用于此代码。
答案 0 :(得分:0)
使用$('option:selected', this).remove();
而不是$("#EmpID").remove(item);