开发者

How to select a select type = multiple - jQuery

What is the best way to select ALL options that are in a <select> th开发者_如何学Pythonat is set as "multiple" ?


Simple using the Has Attribute Selector...

$("select[multiple] option");

This checks for the existence of the multiple attribute on the select tag, and grabs all the options within it.


From the jQuery documentation

.val()

The .val() method is primarily used to get the values of form elements. In the case of <select multiple="multiple"> elements, the .val() method returns an array containing each selected option.

To select all options just use $("select option") or to specifically target multiple use @Josh's answer $("select[multiple] option");

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜