【发布时间】:2014-04-11 21:37:00
【问题描述】:
我想在下拉菜单中通过其'文本选择一个选项。当我运行代码时:
var theText = "Large";
$("#size option:contains(" + theText + ")").attr('selected', 'selected');
它选择 XLarge 而不是 Large。有没有办法让它选择大? JSFiddle:http://jsfiddle.net/r8wuP/2/
【问题讨论】:
-
$("#size option").prop('selected', function() { return $(this).text() === theText; });
标签: javascript jquery drop-down-menu