这是我的HTML
我的问题是为什么在这种情况下没有调用onkey up函数?
<div id="addNewAddress">
<input id="city" type="text" class="autosuggest" placeholder="City">
</div>
$("#city").keyup(function()
{
alert('city');
var city = $(this).val();
var state = $("#state").val();
if(city!=''&&city.length>2)
{
$.ajax({
type: 'GET',
url: url+'/OrderSnacks/oms/autosuggestcity?city='+city+'&state='+state,
jsonpCallback: 'jsonCallback',
cache: true,
dataType: 'jsonp',
jsonp: false,
success: function (responsesss)
{
$( "#city" ).autocomplete({
source: responsesss
});
},
error: function (e)
{
}
});
}
});
我甚至尝试使用
$("#city").on("keyup", function(event){
});
答案 0 :(得分:1)
你需要把它放在$(document).ready(function(){:
上<div id="addNewAddress">
<input id="city" type="text" class="autosuggest" placeholder="City">
</div>
<script>
$(document).ready(function(){
$("#city").keyup(function()
{
alert('city');
var city = $(this).val();
var state = $("#state").val();
if(city!=''&&city.length>2)
{
$.ajax({
type: 'GET',
url: url+'/OrderSnacks/oms/autosuggestcity?city='+city+'&state='+state,
jsonpCallback: 'jsonCallback',
cache: true,
dataType: 'jsonp',
jsonp: false,
success: function (responsesss)
{
$( "#city" ).autocomplete({
source: responsesss
});
},
error: function (e)
{
}
});
}
});
});
</script>