Jquery 仅当“/”是自动完成中的最后一个字符时,如何调用web方法?
每次输入字符时,我的autocomplete函数都会调用web方法。我想在输入字符时调用,字符末尾带有/value 例如:a/ 我的自动完成功能:Jquery 仅当“/”是自动完成中的最后一个字符时,如何调用web方法?,jquery,asp.net,vb.net,jquery-autocomplete,Jquery,Asp.net,Vb.net,Jquery Autocomplete,每次输入字符时,我的autocomplete函数都会调用web方法。我想在输入字符时调用,字符末尾带有/value 例如:a/ 我的自动完成功能: <script type="text/javascript"> function pageLoad(sender, args) { $(function () { $("#<%=txtCu.ClientID %>").autocomplete({ source: functio
<script type="text/javascript">
function pageLoad(sender, args) {
$(function () {
$("#<%=txtCu.ClientID %>").autocomplete({
source: function (request, response) {
$.ajax({
url: '<%=ResolveUrl("~/Webservice.asmx/GetCus") %>',
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) {
}
});
},
select: function (e, i) {
$("#<%=hdnCr.ClientID %>").val(i.item.val);
if (i.item.val == "No Records Found") {
$("#<%=hdnCr.ClientID %>").val(-1);
document.getElementById('<%=txtCu.ClientID%>').value = "";
return false;
}
checkddlcustomerinfo();
},
minLength: 0
}).bind('focus', function () { $(this).autocomplete("search"); })
.data("autocomplete")._renderItem = function (ul, item) {
return $("<li></li>").data("item.autocomplete", item).append("<div><table><tr><td width='200px'>" + item.label + "</td>" + "<td width='110px'>" + item.val.split('~')[6] + "</td>" + "<td>" + item.val.split('~')[4] + "</td></tr></table></div>").appendTo(ul);
};
});
}
请帮帮我。这个怎么样
把这个放在后面
$function{
对于最后一个回答:只需更改以下内容
请不要使用request.term.indexOf/,请尝试使用request.term.search/谢谢您的回复。这对我来说非常紧急。让我试试。@Amit Sonit正在填充以/为字符的数据,例如,如果键入a/则只显示a/p结构,但如果键入a/@Amit SoniTry,则需要所有以a开头的数据使用lastIndexOf方法,因为它将始终返回上次发生的次数从request.term,Answer updated中删除最后一个索引。您能帮我一下吗?我想再添加一个条件,如果按enter键,它将触发事件。@Amitsonic您能告诉我,如果我添加request.term.search/?将做什么吗?以上答案我正在获取所有答案如果输入“a/”则以“a”开头的LUE…但对于“应付基础设施”的值,它无法找到。@useer3672923@Amit soni
var enterFlag = false;
$("#<%=txtCu.ClientID %>").on("keypress",function(e){
if(e.keyCode == 13 || e.which == 13){
enterFlag = true;
}
else
{
enterFlag = false;
}
});
if(request.term.indexOf("/") == (request.term.length-1) && enterFlag)
{
var term = request.term.slice(0,-1);
$.ajax({
url: '<%=ResolveUrl("~/Webservice.asmx/GetCus") %>',
data: "{ 'prefix': '" + 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) {
}
});
}