开发者

jQuery equivalent of radio button "checked" for drop down menu

开发者 https://www.devze.com 2023-01-10 11:23 出处:网络
Probably a simple one, but I need some help. I had some radio buttons and was using the following jQu开发者_StackOverflow社区ery to see which was checked:

Probably a simple one, but I need some help. I had some radio buttons and was using the following jQu开发者_StackOverflow社区ery to see which was checked:

var desc1 = ($('input[name=area]:checked').val());

That worked fine, but I now need to use a drop down menu instead of the radio buttons. I tried the same jQuery and also with "selected" instead of "checked" but no luck. How do I get this to work?

Thanks


What you're trying to get is in fact the value of the <select> element:

$("select").val();


The select is just a single element, the option tags doesn't end up as elements themselves.

Just use the val method to get the value of the selected option:

var desc1 = $('select[name=area]').val();
0

精彩评论

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