开发者

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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜