最近iphone手机升级到10.3.3之后,jquery中的on事件多触发了一次,我是使用on来监听input中内容的变化,从而获取数据,前提是,在之前版本的ios系统中已经android系统中都运行良好,但是系统升级到最新版本就出现这个问题。
举个例子,当input的值为“ 东 ”的时候,是显示东开头的列表,这时候在输入“京” 就搜索到“东京”开头的列表,在android和ios之前版本都测试成功,但是在ios10.3中,输入“京”的时候,还是值搜索到“ 东 ”开头的列表。
代码如下
document.getElementById("from-city-select").addEventListener("input",function(){
debugger
var thisVal = $(this).val().toUpperCase();
var val = document.getElementById("from-city-select").value;
var isFound = true;
var expr = /^[\u4e00-\u9fa5]*$/;
if(!expr.test($.trim(thisVal)) || $.trim(thisVal) == ""){
if($.trim(thisVal) == "" || $.trim(thisVal).length < 3){
isFound = false;
}
}
$("#city_section_airport").remove();
$("dl[id^='city_section_autocomplete']").remove();
if($.trim(thisVal) == ""){
$("#city_section_hot").show();
}else if(isFound){
debugger
$("#city_section_hot").hide();
var url = options.url + (options.url.indexOf("?") >=0 ?"&":"?")+"keyword="+encodeURI(encodeURI($.trim(thisVal)))+"&searchType="+options.type;
if (now.getTime() > exitTime)
$.ajax({
url:options.url,
data:{"keyword":encodeURI($.trim(val)),"searchType":options.type},
dataType:"json"
})
}
});