Javascript to hide selected option

前端 未结 4 1376
伪装坚强ぢ
伪装坚强ぢ 2021-01-23 12:29

I have this code to hide selected options:

function connect()
{
    $(\".selectbox option\").show();
    $(\".selectbox\").each(function(i) { 
        var obj =          


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-23 13:23

    Hiding option elements is not always supported. A more idiomatic approach would be to disable it.

    obj.prop("disabled", true);
    

    Or simplify it like this.

    $(".selectbox option:selected").prop("disabled", true);
    

    Or this.

    $(".selectbox").each(function() { 
         this.options[this.selectedIndex].disabled = true; 
    });
    

提交回复
热议问题