123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- (function ($) {
- $.fn.extend({
- select4: function (options) {
- var defaults = {
- ajax_url: true
- }
- var options = $.extend(defaults, options);
- return this.each(function () {
- var mythis = $(this);
- var search_hide = $('.js_searchHone_list');
- $(document).on("click", ".select4_box li", function () {
- mythis.val($(this).find('a span').attr('title'));
- $(".select4_box").remove();
- search_hide.hide();
- });
- mythis.click(function (event) {
- $('.js_hotHomee_list').show();
- var val = $(this).val();
- $.ajax({
- url: options.ajax_url,
- dataType: "json",
- data: {title: val},
- success: function (data) {
- // console.log(data);
- search_hide.html('');
- if (data.code == 200) {
- $('.js_hotHomee_list').hide();
- search_hide.show();
- var html = '<div class="select4_box"><ul>';
- var price = '';
- var unit = '';
- $.each(data.data, function (k, v) {
- if (v.sale_price == 0 || v.sale_price == null || v.sale_price == '') {
- var price = '待定';
- var unit = '';
- } else {
- price = v.sale_price;
- unit = v.price_unit;
- }
- var vname = v.name;
- if (vname.length > 10) {
- nametext = vname.substring(0, 8) + "...";
- } else {
- nametext = vname;
- };
- html += '<li>';
- html += '<a href="/house/' + v.id + '">';
- html += '<p class="left_name">';
- html += '<span title="' + v.name + '">' + v.name + '</span><em>[' + v.city_name + ']</em>';
- html += '</p>';
- html += '<i>' + price + unit + '</i>';
- html += '</a>';
- html += '</li>';
- });
- html += '</ul></div>'
- $(".select4_box").remove();
- search_hide.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").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").attr('title'));
- } else if (event.keyCode == 13) {
- event.stopPropagation();
- mythis.val($(".select4_box li.active span").attr('title'));
- return false;
- } else {
- mythis.trigger("click");
- }
- });
- });
- }
- });
- })(jQuery);
- $(function () {
- $(".js_puicSearch_text").select4({"ajax_url": "/json/searchresult"});
- $('.js_js_puicSearch_buttom').on('click', function () {
- var inptext = $('.js_puicSearch_text').val();
- window.location.href = '/house/search?name=' + inptext;
- })
- $(document).keydown(function (event) {
- if (event.keyCode == 13) {
- $(".js_js_puicSearch_buttom").click();
- }
- });
- $(document).click(function() {
- $('.js_hotHomee_list,.js_searchHone_list').hide();
- })
- $('.js_yv2_bread_search').on('click',function(e){
- e?e.stopPropagation():event.cancelBubble = true;
- })
- });
|