我正在尝试在本地主机上使用带有 url 选项的自动完成功能。我的 php 文件返回如下;
[ { label: "025170000", value: "18511"},....{ label: "TE-5170V-Special", value: "8464"} ]
例如。
我的 html 代码如下所示;
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Remote datasource</title>
<link rel="stylesheet" href="css/ui-lightness/jquery-ui-1.8.23.custom.css">
<script src="js/jquery-1.8.0.min.js"></script>
<script src="js/jquery-ui-1.8.23.custom.min.js"></script>
<style>
.ui-autocomplete-loading { background: white right center no-repeat; }
</style>
<script>
$(function() {
function log( message ) {
$( "<div/>" ).text( message ).prependTo( "#log" );
$( "#log" ).scrollTop( 0 );
}
$( "#products" ).autocomplete({
source: "auto_complete.php",
minLength: 3,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value );
}
});
});
</script>
</head>
<body>
<div class="demo">
<div class="ui-widget">
<label for="products">Products: </label>
<input id="products" />
</div>
<div class="ui-widget" style="margin-top:2em; font-family:Arial">
Result:
<div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
</div>
</div><!-- End demo -->
我让它与一个字符串数组一起工作,但不能让它与标签 - 值对一起工作。