[英]Populate Selectize Dropdown from PHP
我正在使用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>
您正在使用Selectize jQuery plugin ,並通過Ajax從數據庫中獲取記錄。
和您嘗試的PHP輸出是echo $query_result['GameTitle'];
它只明顯地將結果打印在一行中,您需要的是將$query_result['GameTitle']
放在<option></option>
標記內以偽造元素
因此,PHP輸出將是
echo "<option value='".$query_result['GameTitle']."'>".$query_result['GameTitle']."</option>";
並將在select
元素內填充<option></option>
標簽
<div class="control-group">
<select id="GameDetails_1" name="GameDetails_1" autocomplete="false">
</select>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.