Disable Drop Down Option using jQuery

前端 未结 7 706
时光取名叫无心
时光取名叫无心 2021-01-04 07:35

I need to disable options with value \"- Sold Out -\" in a list of dynamic drop down menus. How can I do this easily with jQuery? Below is the HTML



        
7条回答
  •  有刺的猬
    2021-01-04 07:52

    In case anyone wants to be able to disable a drop down list by text instead of value, here's what I did:

    $("#DDL option").filter(function () {
        return $(this).text() === "Text 1" ||
               $(this).text() === "Text 2" ||
               $(this).text() === "Text 3";
    }).prop("disabled", true);
    

提交回复
热议问题