Get selected option from select element

后端 未结 12 975
温柔的废话
温柔的废话 2020-12-08 01:45

I am trying to get the selected option from a dropdown and populate another item with that text, as follows. IE is barking up a storm and it doesn\'t work in Firefox:

<
12条回答
  •  生来不讨喜
    2020-12-08 02:16

    Given this HTML:

    
    

    Select by description for jQuery v1.6+:

    var text1 = 'Two';
    $("select option").filter(function() {
        //may want to use $.trim in here
        return $(this).text() == text1; 
    }).prop('selected', true);
    

提交回复
热议问题