jQuery get the value from selectbox by its text

This question already has an answer here:

  • Get selected text from a drop-down list (select box) using jQuery 29 answers

  • Try using .text() on the selected option. eg:

    $('select option:selected').text();
    

    Using filter method (exact match):

    $('select option').filter(function(){
        return $(this).text() === '4 Years';
    }).val();
    

    Using :contains selector:

    $('select option:contains(4 Years)').val();
    

    If you want the value of the selected option:

    $('#year').val();
    

    If you want a specific option by its text:

    $("#year option:contains('4 Years')").val();
    

    Regards.

    链接地址: http://www.djcxy.com/p/83114.html

    上一篇: 获取选择标记jQuery的值

    下一篇: jQuery通过其文本从selectbox中获取值