我有一个有5个选择的页面,都有一个类名“ct”。我需要从每个选择中删除值为“X”的选项,同时运行onclick事件。我的代码是:

$(".ct").each(function() {
    $(this).find('X').remove();
   });

我哪里说错了?


当前回答

它工作在选项标签或文本字段:

$("#idname option[value='option1']").remove();

其他回答

当我只是一个删除选项仍然在视图上的ddl,但在html(如果你检查页面)

$("#ddlSelectList option[value='2']").remove(); //removes the option with value = 2
$('#ddlSelectList').val('').trigger('chosen:updated'); //refreshes the drop down list

对于jquery < 1.8,你可以使用:

$('#selectedId option').slice(index1,index2).remove()

删除选定选项的特定范围。

如果选项值没有可用的id或类,可以从下拉列表中删除所有值,如下所示

$(this).find('select').find('option[value]').remove();

删除所有选项

$(".select").empty();

删除所有选项并添加一个空白选项

$(".select").empty().append(new Option('--Select--',''));

尝试删除选定的

$('#btn-remove').click(function () {
    $('.ct option:selected').each(function () {
        $(this).remove();
    });
});