我在网页中使用带有复选框的多个下拉列表。对于多选下拉列表中的复选框,我使用了http://wenzhixin.net.cn/p/multiple-select/中的“ multiple-select.js ”插件 每当提交值后我尝试清除下拉列表中的值,它就不会发生,即值不会消失。如果有其他方法,请建议。这里是我的代码片段:(如果需要更多信息,请回复)
CSHTML代码:
<div class="col-md-2">
<div>
@Html.Label("Genset")
</div>
<div>
@Html.DropDownListFor(model => model.Environment, new List<SelectListItem>
{
new SelectListItem() {Text = "ONT", Value = "ONT"},
new SelectListItem() {Text = "TST", Value = "TST"},
new SelectListItem() {Text = "ACC", Value = "ACC"},
new SelectListItem() {Text = "PrePROD", Value = "PrePROD"},
new SelectListItem() {Text = "PROD", Value = "PROD"}
}, new { @class = "Multiple", multiple = "multiple", style = "width: 126.989px; padding-bottom: 70px;", @id = "ddlEnvironment" })
</div>
</div>
Javascript :
$('#btnSubmit').click(function(){
var env = $('#ddlEnvironment').val();
if ( env == null)
{
//error popup
}
else
{
// submit operation using ajax call
//I have tried below options, nothing is working
$('#ddlEnvironment').attr('value', null);
or
$('#ddlEnvironment').val(null);
or
$('#ddlEnvironment').val('');
}
});
答案 0 :(得分:1)
使用以下代码,您可以取消选中所有值。
$('#ddlEnvironment').multipleSelect('uncheckAll');
您也可以刷新插件
$('#ddlEnvironment').multipleSelect('refresh');
取自 Plugin Documentation (导航至“方法”部分)