选择事件在jquery中的自动完成中不起作用 [英] Select event does not work in autocomplete in jquery

查看:57
本文介绍了选择事件在jquery中的自动完成中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自动完成工作正常但在选择事件中未调用警报。



我尝试过的事情:



< pre lang =Javascript> 
函数SearchText(){

$('#<%= txtPinCode2.ClientID%>')。autocomplete({
minChars:1,
width :6,
source:function(request,response){
$ .ajax({
type:POST,
contentType:application / json; charset = utf- 8,
url:scm / BranchSearch.ashx?act = bnkb& BankCode =+ $('#<%= ddlBank.ClientID%>:selected')。val()+& PinCode =+ $('#<%= txtPinCode2.ClientID%>')。val(),
data:{},
dataType:json,
success:function(data){
mydata = new Array();
for(var i = 0; i< data.length; i ++){
mydata.push({
label:data [i] .BankBra nchName,
value:data [i] .BanckBranchCode
});

} // for循环结束

//设置搜索以搜索标签和描述
var matcher = new RegExp($。ui.autocomplete .escapeRegex(request.term),i);
响应($。grep(mydata,function(arrItem){
return matcher.test(arrItem.label);
}));

},
select:function(e,ui){
alert(ui.item.label)

},
error :function(result){
alert(No Match);
}
});
}

});
}

解决方案

('#<%= txtPinCode2.ClientID%>')。autocomplete({
minChars:1,
width:6,
source:function(request,response){


.ajax({
type:POST ,
contentType:application / json; charset = utf-8,
url:scm / BranchSearch.ashx?act = bnkb& BankCode =+


< blockquote>('#<%= ddlBank.ClientID%>:selected')。val()+& PinCode =+


Autocomplete is working but alert is not called in select event.

What I have tried:

<pre lang="Javascript">
function SearchText() {

            $('#<%=txtPinCode2.ClientID%>').autocomplete({
                minChars: 1,
                width: 6,                
                source: function (request, response) {
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "scm/BranchSearch.ashx?act=bnkb&BankCode=" + $('#<%=ddlBank.ClientID %> :selected').val() + "&PinCode=" + $('#<%=txtPinCode2.ClientID%>').val(),
                        data: "{}",
                        dataType: "json",
                        success: function (data) {
                            mydata = new Array();
                            for (var i = 0; i < data.length; i++) {
                                mydata.push({
                                    label: data[i].BankBranchName,
                                    value: data[i].BanckBranchCode
                                });

                            }  //end of for loop

                            //setup the search to search the label and the description
                            var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
                            response($.grep(mydata, function (arrItem) {                               
                                return matcher.test(arrItem.label);
                            }));

                        },
                        select: function (e,ui) {
                            alert(ui.item.label)
                                                   
                        },                        
                        error: function (result) {
                            alert("No Match");
                        }
                    });
                }

            });
        }

解决方案

('#<%=txtPinCode2.ClientID%>').autocomplete({ minChars: 1, width: 6, source: function (request, response) {


.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "scm/BranchSearch.ashx?act=bnkb&BankCode=" +


('#<%=ddlBank.ClientID %> :selected').val() + "&PinCode=" +


这篇关于选择事件在jquery中的自动完成中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆