gpt4 book ai didi

php - 如何将 jQuery 自动完成文本框与 DataTables 结合使用

转载 作者:行者123 更新时间:2023-11-30 01:30:59 25 4
gpt4 key购买 nike

我正在使用 jQuery UI DataTables,它运行顺利。

我有大约 20 个奇怪的过滤选项。有些是下拉菜单,有些是日期选择器和相当多的文本框。我想让这些文本框自动完成数据库中的数据。

我已经断断续续地用它敲头一个星期了。

如果可以的话,是否可以使用数据表自动完成,如何实现?

任何建议都将成为救星。

enter image description here

最佳答案

试试这个..你使用 php,所以它会像这样。

jQuery

$(document).ready(function() {

var LocalityArray = [];
//$.getJSON('../../database/country.json', { id: data.id }, function(response) {
$.getJSON("locality.php", { getLocality: '495074' }, function(response) {
// Here (response) is array format. Like this

// [{"LocalityID":9397,"CityID":55,"LocalityName":"Adugodi"},{"LocalityID":9398,"CityID":55,"LocalityName":"Aga Abbas Ali Road"},{"LocalityID":9399,"CityID":55,"LocalityName":"Agaram"},{"LocalityID":9400,"CityID":55,"LocalityName":"Agrahara Dasara Halli"},{"LocalityID":9401,"CityID":55,"LocalityName":"Agrahara Dasarahalli"},{"LocalityID":9402,"CityID":55,"LocalityName":"Airport Exit Road"},{"LocalityID":9403,"CityID":55,"LocalityName":"Horamavu"},{"LocalityID":9404,"CityID":55,"LocalityName":"Hosakere Halli"},{"LocalityID":9405,"CityID":55,"LocalityName":"Hennur"},{"LocalityID":9406,"CityID":55,"LocalityName":"Hesaraghatta"},{"LocalityID":9407,"CityID":55,"LocalityName":"HKP Road"},{"LocalityID":9408,"CityID":55,"LocalityName":"HMT Layout"},{"LocalityID":9409,"CityID":55,"LocalityName":"Hongasandra"},{"LocalityID":9410,"CityID":55,"LocalityName":"Hoody"},{"LocalityID":9411,"CityID":55,"LocalityName":"Hayes Road"} ]

$.each(response, function(key, value) {
LocalityArray[key] = value.LocalityName;
});

$(".txtLocality").autocomplete({
minLength: 2,
source: LocalityArray
});
}, 'json');

});

HTML

<table>
<tr>
<td>
<input type="text" class="txtLocality" />
<input type="text" class="txtLocality" />
<input type="text" class="txtLocality" />
</td>
</tr>
</table>

关于php - 如何将 jQuery 自动完成文本框与 DataTables 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17464937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com