123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- (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:{name:val},
- success:function(data){
- mythis2.html('');
- if(data.code == 200){
- var html = '<div class="select4_box"><ul>';
- var nametext ="";
- $.each(data.data,function(k,v){
- var nemeleng=v.subject;
- if(nemeleng != "undefined" && nemeleng != undefined){
- if (nemeleng.length>8) {
- nametext=nemeleng.substring(0,8)+"...";
- }else{
- nametext=nemeleng;
- };
- }
- html += '<li class="c"><a href="/news/details/'+v.id+'/">'+nametext+'</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":"/news/homeform"}); //需要填写接口
- $('.back_search_m .form a.submit').on('click',function(){
- var inptext=$('.y_headerscr').val();
- AjaxFn(inptext);
- })
- // 封装 ajax 方法
- function AjaxFn(txt){
- // console.log(txt)
- $.ajax({
- type: 'POST',
- url: '/news/homeform?name='+txt, //需要填写接口
- dataType: 'json',
- success: function(data){
- if(data.code == 200){
- $('.news_list .ns').html(ModuleWay(data.data)); //调用选择模块
- }else if(data.code == 300){
- $('.news_list .ns').html('<div class="wint"><img src="/image/icon-w.png" alt=""></div>');
- }
- },
- error: function(xhr, type){
- }
- });
- }
- function ModuleWay(conditions){
- var _html="";
- $.each(conditions.data,function (key,val) {
- _html +='<div class="plan_one">';
- _html +='<a href="/news/details/'+val.id+'/">';
- _html +='<div class="plan_one_title">';
- _html +='<p class="text">'+val.subject+'</p>';
- _html +=' <p> <span class="guis">'+val.source+' </span><i>·</i><span class="data">'+val.open_time+'</span></p>';
- _html +='</div>';
- _html +='<div class="plan_one_img"><img src="'+conditions.url+val.thumb[0]+'" alt=""></div>';
- _html +='</a>';
- _html +='</div>';
- })
- return _html ;
- }
- // $(document).keydown(function(event){
- // if(event.keyCode==13){
- // $(".y_lpsubmit").click();
- // }
- // });
- // 输入清除显示与隐藏
- $('.index_form input[type="search"]').on('keyup',function(){
- var txt = $(this).val();
- if(txt != ''){
- $('.index_form .w_cls').show();
- }else{
- $('.index_form .w_cls').hide();
- }
- })
- // 清除功能
- $('.index_form .w_cls').on('click',function(){
- $('.index_form input[type="search"]').val('');
- $(this).hide();
- })
- });
- // function search(){
- // var inptext=$('.y_headerscr').val();
- // window.location.href = '/house/news?name='+inptext;
- // }
- $('.m_lplist_inp').on('click',function(){
- $('.news_search_box').show();
- })
- $('.back-btn').on('click',function(){
- $('.news_search_box').hide();
- })
|