How can I check whether a option already exist in select by JQuery

后端 未结 8 879
余生分开走
余生分开走 2020-11-30 19:22

How can I check whether a option already exist in select by JQuery?

I want to dynamically add options into select and so I need to check whether the option is alread

8条回答
  •  自闭症患者
    2020-11-30 19:59

    It's help me :

      var key = 'Hallo';
    
       if ( $("#chosen_b option[value='"+key+"']").length == 0 ){
       alert("option not exist!");
    
        $('#chosen_b').append("");
        $('#chosen_b').val(key);
       $('#chosen_b').trigger("chosen:updated");
                             }
      });
    

提交回复
热议问题