(function($){
$.fn.extend({
select4:function(options){
var defaults = {
ajax_url:true
}
var options = $.extend(defaults, options);
return this.each(function(){
var mythis = $(this);
var mythis2 = $('.y_scriptm');
$(document).on("click",".select4_box li",function(){
mythis.val($(this).find('a span.y_left').attr('title'));
$(".select4_box").remove();
});
$(document).click(function(event) {
$(".select4_box").remove();
});
$(".select4_box").click(function(event) {
event.stopPropagation();
});
mythis.click(function(event) {
var val = $(this).val();
$.ajax({
url:options.ajax_url,
dataType:"json",
data:{title:val},
success:function(data){
mythis2.html('');
if(data.code == 200){
var html = '
';
$.each(data.data,function(k,v){
var nemeleng=v.name;
if (nemeleng.length>20) {
var nametext=nemeleng.substring(0,18)+"...";
}else{
var nametext=nemeleng;
};
html += '- '+nametext+'['+v.city_name+']
';
});
html+='
'
$(".select4_box").remove();
mythis2.html(html);
}
}
});
});
mythis.keyup(function(event) {
if(event.keyCode==40){
var index = $(".select4_box li.active").index()+1;
$(".select4_box li").eq(index).addClass('active').siblings().removeClass('active');
mythis.val($(".select4_box li.active span.y_left").attr('title'));
}else if(event.keyCode==38){
var index = $(".select4_box li.active").index()-1;
if(index<0){
index = $(".select4_box li").length-1;
}
$(".select4_box li").eq(index).addClass('active').siblings().removeClass('active');
mythis.val($(".select4_box li.active span.y_left").attr('title'));
}else if(event.keyCode==13){
event.stopPropagation();
mythis.val($(".select4_box li.active span.y_left").attr('title'));
return false;
}else{
mythis.trigger("click");
}
});
});
}
});
})(jQuery);
$(function(){
$(".search_input").select4({"ajax_url":"/house/searchname"});
$('a#search_butt').on('click',function(){
search();
})
$(document).keydown(function(event){
if(event.keyCode==13){
search();
}
});
});
function search(){
var inptext=$('.search_input').val();
window.location.href = '/house/search?name='+inptext;
}