123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- (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>';
- 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 += '<li class="c"><a href="/house/' + v.id + '"><span class="y_left" title="' + v.name + '"><em>' + nametext + '</em><i>[' + v.city_name + ']</i></span><span class="y_right"><em>' + price + '</em>' + unit + '</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 () {
- $(".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;
- }
|