(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 = '
';
var price = '待定';
var unit = '';
$.each(data.data, function (k, v) {
if (v.sale_price != '' && v.sale_price != null && v.sale_price != 0) {
price = v.sale_price;
unit = v.price_unit;
}
var nemeleng = v.name;
if (nemeleng.length > 8) {
var nametext = nemeleng.substring(0, 8) + "...";
} else {
var nametext = nemeleng;
}
;
html += '- ' + nametext + '[' + v.city_name + ']' + price + '' + unit + '
';
});
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 () {
$(".y_headerscr").select4({"ajax_url": "/json/searchname"});
$('.back_search_m .form a').on('click', function () {
var inptext = $('.y_headerscr').val();
window.location.href = '/house/search?name=' + inptext;
})
$(document).keydown(function (event) {
if (event.keyCode == 13) {
$(".y_lpsubmit").click();
}
});
});
function search() {
var inptext = $('.y_headerscr').val();
window.location.href = '/house/search?name=' + inptext;
}