我有一个应用了自动完成功能的文本框,它会在键入任何字母时填充列表数据,但是我想在文本框上双击显示总列表。
以下是我使用的代码:
<script type="text/javascript">
$(document).ready(function () {
$("#<%=tNALkTxt.ClientID %>").autocomplete({
source: function (request, response) {
$.ajax({
url: '<%=ResolveUrl("~/WebService.asmx/Get") %>',
data: "{ 'prefix': '" + request.term + "'}",
dataType: "json",
type: "POST",
scroll: true,
scrollHeight: 180,
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) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
},
select: function (e, i) {
$("#<%=rtCmbHdn.ClientID %>").val(i.item.val);
},
minLength: 1
});
});
</script>
在双击文本框时,我需要添加哪些附加功能来填充完整列表。
答案 0 :(得分:1)
试试这个:
$(document).ready(function () { $("#").autocomplete({ source: function (request, response) { $.ajax({ url: '', data: "{ 'prefix': '" + request.term + "'}", dataType: "json", type: "POST", scroll: true, scrollHeight: 180, 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) { alert(response.responseText); }, failure: function (response) { alert(response.responseText); } }); }, select: function (e, i) { $("#").val(i.item.val); }, minLength: 1 }).bind("dblclick",function () { $(this).autocomplete("search", ""); }) }); ; });
答案 1 :(得分:0)
我明白了,这是代码
<script type="text/javascript">
$(document).ready(function () {
$("#<%=tNALkTxt.ClientID %>").autocomplete({
source: function (request, response) {
$.ajax({
url: '<%=ResolveUrl("~/WebService.asmx/Get") %>',
data: "{ 'prefix': '" + request.term + "'}",
dataType: "json",
type: "POST",
scroll: true,
scrollHeight: 180,
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) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
},
select: function (e, i) {
$("#<%=rtCmbHdn.ClientID %>").val(i.item.val);
},
minLength: 0
}).bind('focus', function () { $(this).autocomplete("search"); });
});
</script>