如何使用jQuery在下拉列表中通过文本值选择项目?

问题描述:

如果我有以下选择,并且不知道用于提前选择一个项目的值,就像在这个问题或我想要选择的项目的索引,如果我知道如C选项那样的文本值,我如何可以使用jQuery选择一个选项?

If I had the following select, and did not know the value to use to select an item in advance like in this question or the index of the item I wanted selected, how could I select one of the options with jQuery if I did know the text value like Option C?

<select id='list'>
<option value='45'>Option A</option>
<option value='23'>Option B</option>
<option value='17'>Option C</option>
</select>


var option;
$('#list option').each(function() {
    if($(this).text() == 'Option C') {
        option = this;
        return false;
    }
});