123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- (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 = '<div class="select4_box"><ul>';
- $.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 += '<li class="c"><a href="/house/'+v.id+'/"><span class="y_left" title="'+v.name+'"><em>'+nametext+'</em><i>['+v.city_name+']</i></span></a></li>';
- });
- html+='</ul></div>'
- $(".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;
- }
|