【发布时间】:2014-04-21 09:23:02
【问题描述】:
我的文本框有自动完成功能。我想用新列以表格格式显示更多数据。
到目前为止我的代码:
<script type="text/javascript">
function CNo(sender, args) {
$(function () {
$("#<%=txtCNo.ClientID %>").autocomplete({
source: function (request, response) {
$.ajax({
url: '<%=ResolveUrl("~/Webservice.asmx/GettxtCNo") %>',
data: "{ 'prefix': '" + request.term + "'}",
dataType: "json",
type: "POST",
async: false,
mustMatch: true,
contentType: "application/json; charset=utf-8",
success: function (data) {
response($.map(data.d, function (item) {
return {
label: item.split('^')[0],
val: item.split('^')[1]
}
}))
},
error: function (response) {
},
failure: function (response) {
}
});
$.ui.autocomplete.prototype._renderMenu = function (ul, items) {
var self = this;
ul.append("<table><thead><tr><th>Name</th><th>City</th></tr></thead><tbody></tbody></table>");
$.each(items, function (index, item) {
self._renderItem(ul.find("table tbody"), item);
});
};
$.ui.autocomplete.prototype._renderItem = function (table, item) {
return $("<tr></tr>")
.data("item.autocomplete", item)
.append("<td>" + item.value + "</td>" + "<td>" + item.val.split('~')[6] + "</td>")
.appendTo(table);
};
},
select: function (e, i) {
$("#<%=hdnCNo.ClientID %>").val(i.item.val);
if (i.item.val == "No Records Found") {
$("#<%=hdnCNo.ClientID %>").val(-1);
document.getElementById('<%=txtCNo.ClientID%>').value = "";
return false;
}
checktxtCNorinfo();
},
minLength: 0
}).bind('focus', function () { $(this).autocomplete("search"); });
});
}
</script>
在此代码中,我在自动完成列表中得到结果,但无法从列表中选择任何项目。我错在哪里?
【问题讨论】:
标签: jquery asp.net vb.net jquery-autocomplete jquery-ui-autocomplete