$('#remove').click(function() {
var foo = [];
$('#FeatureLists :selected').each(function(i, selected) {
foo[i] = $(selected).text();
alert(foo[i]);
if (foo[i] != "Add" )
return !$('#FeatureLists option:selected').remove();
if (foo[i] != "Edit")
return !$('#FeatureLists option:selected').remove();
});
});
我的选择中有六个项目,其中 4 个是添加、编辑、删除 View ,它是多选列表,我不希望用户删除这 4 个项目,除了他们可以删除任何项目。我该怎么做?上面的代码中没有发生这种情况
最佳答案
首先,根据您的示例代码,似乎不需要数组 foo
。其次,if语句需要包含所有需要用OR
条件排除的项目,如下所示:
if (foo[i] == "Add" ||
foo[i] == "Edit" ||
foo[i] == "Delete" ||
foo[i] == "View")
{
return;
}
else
{
$(selected).remove();
}
关于jquery - asp.net mvc jquery 删除选择列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2979564/