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

前端 未结 6 847
说谎
说谎 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条回答
  •  萌比男神i
    2021-02-12 20:06

    The first time where you refer to this it is not a jQuery object it is a DOM object and a DOM object doesn't have the val() method. You should either use this.value och $(this).val() try this:

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

提交回复
热议问题