jQuery - disable selected options

前端 未结 4 1264
心在旅途
心在旅途 2020-12-01 05:13

Need to disable already selected options in select box using jQuery. I\'d like it to grey out like asmselect.

Test my example here.

//JS
$(\"#theSele         


        
4条回答
  •  醉梦人生
    2020-12-01 05:41

    This will disable/enable the options when you select/remove them, respectively.

    $("#theSelect").change(function(){          
        var value = $(this).val();
        if (value === '') return;
        var theDiv = $(".is" + value);
    
        var option = $("option[value='" + value + "']", this);
        option.attr("disabled","disabled");
    
        theDiv.slideDown().removeClass("hidden");
        theDiv.find('a').data("option",option);
    });
    
    
    $("div a.remove").click(function () {     
        $(this).parent().slideUp(function() { $(this).addClass("hidden"); });
        $(this).data("option").removeAttr('disabled');
    });
    

    Demo: http://jsfiddle.net/AaXkd/

提交回复
热议问题