jquery selection if option.value equal something, mark a selected

前端 未结 6 754
说谎
说谎 2021-02-12 19:45

I have some question about jquery selection. In my case, how to match if the option.value equal something, mark a selected for it. Online code here

6条回答
  •  一生所求
    2021-02-12 20:02

    try below

        $("div#selection select.select").val(num);
    

    if your select box is multiple select, you can try

        $("div#selection select.select option").each(function(){
          if($(this).val()==num){ 
            $(this).attr("selected", true);    
          }
       });
    

提交回复
热议问题