您可以使用JQuery select2并对其应用搜索方法,该方法将通过AJAX调用获取数据。我使用JSON填充select。我在这里添加示例代码,根据您的要求进行修改。
示例HTML
<select name="ItemID" id="ItemID">
<option value="0">--</option>
</select>
相关javascript
$("#ItemID").select2({
minimumInputLength:3,
ajax: {
url: 'json/getItemList.php',
dataType: 'json',
data: function (params) {
return {
Src: params.term
};
},
processResults: function (data) {
var items = [];
for (var i = 0; i < data.length; ++i) {
items.push({id: data[i][0], text: data[i][1]});
}
return {
results: items,
}
},
},
});
相关PHP代码
<?php
$Src = "";
if(isset($_REQUEST['Src']))
$Src = $_REQUEST['Src'];
// Write your own code to fetch data, and replace the below line
//$oList = $mdb->getItemListJSON3($tcmp->getCompanyID(), $Src, 2);
$jsonStr = json_encode($oList);
print($jsonStr);
?>