$(document).ready(function () {
if(navigator.userAgent.indexOf("MSIE")>0){
document.getElementById('alreadysearch').attachEvent("onpropertychange",alreadyajax);
document.getElementById('nosearchvalue').attachEvent("onpropertychange",noinajax);
}else {
document.getElementById('alreadysearch').addEventListener("input",alreadyajax,false);
document.getElementById('nosearchvalue').addEventListener("input",noinajax,false);
}
});
function ajaxAddOptions(url,target,text) {
target.empty();
$.getJSON(url,function(json){
$(json).each(function(i) {
var x = json[i];
target.append("");
});
});
}
function alreadyajax(){
var key = $("#alreadysearch").val();
ajaxAddOptions("/avatar/searhost/in/{{file_id}}/?key="+key, $("#alreadlist"), "hostgroup");
}
function noinajax(){
var key = $("#nosearchvalue").val();
ajaxAddOptions("/avatar/searhost/no/{{file_id}}/?key="+key, $("#nolist"), "hostgroup");
}
可以自己封装一些常用的JS代码。做成JQuery的插件 !