jQuery: set selected value of dropdown list?

后端 未结 3 732
我在风中等你
我在风中等你 2021-02-01 02:47

What\'s wrong with this code?

jQuery

$(document).ready(function() {
    $(\"#routetype\").val(\'quietest\');
)};

HTML

&         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-01 03:04

    UPDATED ANSWER:

    Old answer, correct method nowadays is to use jQuery's .prop(). IE, element.prop("selected", true)

    OLD ANSWER:

    Use this instead:

    $("#routetype option[value='quietest']").attr("selected", "selected");
    

    Fiddle'd: http://jsfiddle.net/x3UyB/4/

提交回复
热议问题