我需要判断<select>
是否有文本等于特定值的选项.
例如,如果有<option value="123">abc</option>
,我会查找"abc".
有没有 Select 器来做这件事?
我在找类似于$('#select option[value="123"]');
的东西,不过是为了文字.
我需要判断<select>
是否有文本等于特定值的选项.
例如,如果有<option value="123">abc</option>
,我会查找"abc".
有没有 Select 器来做这件事?
我在找类似于$('#select option[value="123"]');
的东西,不过是为了文字.
这可能有助于:
$('#test').find('option[text="B"]').val();
这将为您提供文本为B
的选项,而不是文本包含B
的选项.
For recent versions of jQuery the above does not work.正如下面Quandary人 comments 的那样,这就是jQuery 1.9.1的工作原理:
$('#test option').filter(function () { return $(this).html() == "B"; }).val();