我得到一个 HTML select
选项,它是用 PHP 生成的。选项的名称是目录中的文件夹。现在我需要 jQuery 脚本中的值。我只知道命令 $('#select :selected').text()
或 $(#select).val()
但两者都只是给我带来当前选择的选项。
使用 PHP 的选择框:
<select id="existAlbum" name="existAlbum" size="1">
<option>SELECT ALBUM</option>
<?PHP
foreach ($alledateien as $datei) {
$dateiinfo = pathinfo($album."/".$datei);
if ($datei != "." && $datei != ".." && $datei != "background.jpg" && $datei != "loading.gif") {
echo ('<option>' . $datei . '</option>');
};
};
?>
</select>
是否可以添加 jQuery 数组中的所有值?
我需要将选项值与其他单词进行比较。
最佳答案
$(function(){
var optionValues = [];
$('#existAlbum option').each(function(){
optionValues.push(this.value);
//or if you want to use the jquery methods on each option:
//$(this).val()
//with your current code, you would need $(this).text(),
//since youre not adding any values
//"this" is the current DOM element (<option>)
});
//do stuff with the optionValues-array here
});
关于jquery - 使用 jQuery 选择 HTML 选择的所有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13099063/