jQuery remove options from select

后端 未结 8 916
一生所求
一生所求 2020-11-28 02:58

I have a page with 5 selects that all have a class name \'ct\'. I need to remove the option with a value of \'X\' from each select while running an onclick event. My code is

8条回答
  •  离开以前
    2020-11-28 03:31

    Iterating a list and removing multiple items using a find. Response contains an array of integers. $('#OneSelectList') is a select list.

    $.ajax({
        url: "Controller/Action",
        type: "GET",
        success: function (response) {
            // Take out excluded years.
            $.each(response, function (j, responseYear) {
                $('#OneSelectList').find('[value="' + responseYear + '"]').remove();
            });
        },
        error: function (response) {
            console.log("Error");
        }
    });
    

提交回复
热议问题