开发者

How to select a select type = multiple - jQuery

开发者 https://www.devze.com 2023-02-11 04:22 出处:网络
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...

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

精彩评论

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