//获取url中的参数 function getUrlParam(name) { //构造一个含有目标参数的正则表达式对象 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //匹配目标参数 var r = window.location.search.substr(1).match(reg); //alert(r); //返回参数值 if (r != null) return decodeURI(r[2]); return null; } // 筛选 选中效果 var _city = getUrlParam('city'); //价格 if (_city) { var _index = $('.wrapper02 .scroller li[country="' + _city + '"]').index(); } ; // console.log(_index); // //导航移动 demo示例六 通过id调取 $('#demo06').navbarscroll({ defaultSelect: _index, //默认选中 scrollerWidth: 4, fingerClick: 1, endClickScroll: function (obj) { // console.log(obj.text()) } }); function getParams(url) { var theRequest = new Object(); if (!url) url = location.href; if (url.indexOf("?") !== -1) { var str = url.substr(url.indexOf("?") + 1) + "&"; var strs = str.split("&"); for (var i = 0; i < strs.length - 1; i++) { var key = strs[i].substring(0, strs[i].indexOf("=")); var val = strs[i].substring(strs[i].indexOf("=") + 1); theRequest[key] = val; } } return theRequest; } var objUrl = {}; //获取get参数 var url = window.location.href; var searchParams = ''; //最后拼接的参数 var urlParams = ''; // 页数 var page = 1; // 每页展示5个 var size = 4; var params = getParams(url); //获取get请求的参数 if (!$.isEmptyObject(params)) { $.each(params, function (key, val) { if (key == 'city') feng_cityTel = val; objUrl[key] = val; urlParams += key + '=' + val + '&'; }) urlParams = urlParams.substring(0, urlParams.length - 1); searchParams = '&' + urlParams; } var country = $('.m_click li').eq(0).attr('country'); $('.m_click li').on('click', function () { var _this = $(this); country = $(this).attr('country'); var ParamsArr = ['city']; //搜索字段 var atrName = _this.attr('name'); var _val = _this.attr('country'); var urlParams = ''; for (var k in ParamsArr) { if (ParamsArr[k] == atrName) { objUrl[atrName] = _val; delete objUrl.page; } } $.each(objUrl, function (key, val) { if (key == 'py') return true; //跳出当前循环 urlParams += key + '=' + val + '&'; }) var cityUrl = ''; urlParams = urlParams.substring(0, urlParams.length - 1); if (typeof objUrl.py == 'string') { cityUrl = 'py=' + objUrl.py + '&'; } if (urlParams == '' && cityUrl != '') { cityUrl = cityUrl.substring(0, cityUrl.length - 1); } // console.log(urlParams); window.location.href = '?' + cityUrl + urlParams; }) $(function () { $('.m_lplist_box').dropload({ scrollArea: window, domDown: { domClass: 'dropload-down', domRefresh: '
↑上拉加载更多
', domLoad: '
加载中...
', domNoData: '
我也是有底线的...
' }, loadDownFn: function (me, da) { page++; // 拼接HTML var requesturl = ''; if (url.indexOf('city') > -1) { requesturl = 'live/home/getlive?page=' + page + '&limit=' + size + searchParams; } else { requesturl = 'live/home/getlive?page=' + page + '&limit=' + size + searchParams + '&city=' + country; } var result = ''; $.ajax({ type: 'GET', url: requesturl, dataType: 'json', async: false, success: function (data) { var data = data.data; // console.log(data); if (data != null) { $.each(data, function (key, val) { result += '
  • '; result += ''; result += '
    '; result += '

    '; switch (val.state) { case '直播中': //直播中 result += '·直播中'; break; case '预告': //预告 result += '预告'; result += '' + val.time + ''; break; case '回放': //回放 result += '回放'; break; } result += '

    '; result += ''; result += '
    '; result += '
    '; result += '' + val.title + ''; result += '

    '; result += '' + val.house.f.city_name + ' ' + val.city_name + ' '; // result+='浏览量: '+val.number+''; result += '

    '; result += '
    '; result += '
    '; result += '
  • '; }) $('.m_lplist_box ul').append(result); // 如果没有数据 } else { // 锁定 me.lock(); // 无数据 me.noData(); } me.resetload(); // 为了测试,延迟1秒加载 // setTimeout(function(){ // // 插入数据到页面,放到最后面 // $('.y_hotnews_list ul').append(result); // // 每次数据插入,必须重置 // me.resetload(); // },100); }, error: function (xhr, type) { // alert('Ajax error!'); // 即使加载出错,也得重置 me.resetload(); } }); } }); });