joh*_*ohn 2 html javascript jquery
我知道如何使用jquery在html下拉菜单中获取所选值.
但是,我想在下拉列表中获取所有值的数组(即,包含每个<option>标记的值的数组<select>),无论选择的是什么.这样做的正确方法是什么?
非常简单,使用一些选择器和$.each:
$('select#id_of_select_if_you_want option').each(function(idx, val)
{
$(val).val(); // here's the value
$(val).html(); // here's the display text
});
Run Code Online (Sandbox Code Playgroud)