How can I set the value of a DropDownList using jQuery by checking the value ends with a specific string?
I need to be able to select a value in a dropdownlist by the first option that ends in a specific string.
If I have three options...
Peas
Cheese
Fleas
... I want to be able to select the option ending in 'ese'. I need this to be case insensitive too.
Something like $("#mydropdownlist").val().match("ese$");
Any help is appre开发者_运维问答ciated.
$("option[value$='ese']:first").attr("selected","selected");
source: http://api.jquery.com/attribute-ends-with-selector/
online demo: http://jsfiddle.net/tg4S2/
精彩评论