我正在使用 Selectize jQuery 插件,并希望使用 PHP 输出的结果填充下拉框。我能够获取框中的数据,但有多个选项,并且将它们全部放在一行而不是单独的选项。有什么想法吗?
jQuery
$("#SearchForm_1").submit(function() {
$.post($(this).attr("action"),
$(this).serialize(),
function(data) {
var selectize_tags = $("#GameDetails_1")[0].selectize;
selectize_tags.addOption({
text:data,
value: data
});
selectize_tags.addItem(data);
});
);
});
$('#GameDetails_1').selectize({
selectOnTab:true
});
HTML
<div class="control-group">
<select id="GameDetails_1" name="GameDetails_1" autocomplete="false">
</select>
</div>
PHP 输出
echo $query_result['GameTitle'];
最佳答案
就这么简单吗?
<div class="control-group">
<select id="GameDetails_1" name="GameDetails_1" autocomplete="false">
<?php echo '<option value="">' . $query_result['GameTitle'] . '</option>'; ?>
</select>
</div>
关于javascript - 从 PHP 填充选择下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32926584/