我的自动完成脚本有问题, 所需的结果是当我键入例如BG或BRIGHT GREEN以获得结果“BG”
时 <?php
$colours =
[
'LG'=>'LIGHT GREEN',
'BG'=>'BRIGHT GREEN',
'DR'=>'DARK RED',
];
?>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<form id="frm" method="post">
<input id="color" type="text" >
</form>
<script>
var colorObj = <?php echo json_encode($colours); ?>;
$("#color").autocomplete({
source:colorObj,
minLength: 2,
select: function(event, ui) {
event.preventDefault();
$("#color").val(ui.item.label);
}
});
</script>