【发布时间】:2019-12-16 16:56:19
【问题描述】:
我希望能够使用自动完成功能来搜索标签列表,然后发布值。这已成功完成。问题是选择标签时,它会更改为值。因此,用户选择了一个自动完成的值,比如 burger,但在选择时,它会更改为 id,比如 18。在帖子中,它实际上发送了正确的信息,即 id。当人们在选择时看到一个数字而不是一个值时,这可能会让他们感到困惑。第一次使用jquery,如果简单的话请见谅。
数据库提取get_meals.php:
while($row = $stmt->fetch()) {
$return_arr[] = array('value'=>$row['food_id'], 'label' => $row['food']);
}
这里是 jquery:
<script type="text/javascript">
$(function() {
$(".auto").autocomplete({
source: "get_meals.php",
minLength: 0
});
});
</script>
尝试过类似的东西:
select: function (event, ui) {
event.preventDefault();
$(this).val(ui.item.label);
focus: function(event, ui) {
$("#search").val(ui.item.label);
return false; // Prevent the widget from inserting the value.
select: function(event, ui) {
$('#search').val(ui.item.label);
$('#searchval').val(ui.item.value);
return false; // Prevent the widget from inserting the value.
},
focus: function(event, ui) {
$("#search").val(ui.item.label);
return false; // Prevent the widget from inserting the value.
【问题讨论】:
标签: jquery autocomplete