本文介绍了如何通过使用Jquery在文本框中编写一个字符来获取城市的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Team,

我想通过写一个字符来获得城市名称。

例如:

i在我的网页中有两个文本框,即CityTextbox和State Textbox

如果我写单词H,我想要城市从H开始,即海德拉巴,喜马偕尔邦......等等,我没有得到。请帮助我,如何得到它?

我在SQL表中有城市和州的数量。

我的功能如下:



Hello Team,
I want a city name by writing the one character.
for example :
i have two textbox in my Web Page that is CityTextbox and State Textbox
if i write the word H ,i want the city started from H that is hyderabad,Himachal Pradesh ... and so on which i am not getting.Please kindly help me, how to get it?
I have the number of city and state in SQL Table.
I have the function as follow:

var cityList = [];
        var stateList = [];

<pre lang="cs">function setFocusLostEvents() {

           $(&#39;#txtCity&#39;).focusout(function () {

               var states = $.grep(cityAndStateList, function (item, index) {

                   return $(&#39;#txtCity&#39;).val().toLowerCase() == item.City.toLowerCase()
               });

               $(&#39;#txtState&#39;).val(&#39;&#39;);
               if (states != null &amp;&amp; states.length &gt; 0) {
                   $(&#39;#txtState&#39;).val(states[0].State);
               }
           });
       }</pre>





函数bindStateAndCityDropDown(){

$ .each(cityAndStateList,function(i,item) ){

cityList.push(item.City);

if($ .inArray(item.State,stateList)< 0){

stateList.push(item.State);

}

});



$( #txtCity)。autocomplete({

source:cityList,

select:function(e,i){

$(#txtCity ).val(i.item.val);

},

minLength:1

});



$(#txtState)。autocomplete({

source:stateList,

select:function(e,i){
$(#txtState)。val(i.item.val);

},

minLength:1

});

}



我应该在哪里修改代码。

谢谢

Harshal Raut



function bindStateAndCityDropDown() {
$.each(cityAndStateList, function (i, item) {
cityList.push(item.City);
if ($.inArray(item.State, stateList) < 0) {
stateList.push(item.State);
}
});

$("#txtCity").autocomplete({
source: cityList,
select: function (e, i) {
$("#txtCity").val(i.item.val);
},
minLength: 1
});

$("#txtState").autocomplete({
source: stateList,
select: function (e, i) {
$("#txtState").val(i.item.val);
},
minLength: 1
});
}

Where should i modify the code.
Thanks
Harshal Raut

推荐答案




这篇关于如何通过使用Jquery在文本框中编写一个字符来获取城市的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 07:31