/** * Created by luocj on 2016/7/26. */ var cur = ""; var pagesize = 10; // 模糊搜索 $("#text1").click(function(e){ e.stopPropagation(); $(".xiala").removeClass("hide"); }); $(document).click(function(){ if(!$(".xiala").hasClass("hide")){ $(".xiala").addClass("hide"); } }); function myFunction() { var text1 = $("#text1").val(); $.ajax({ url:'./st-xm/Model/line/searchLine.php', type: "post", data: {lineName:text1,currpage:cur}, dataType: "json", success: function (data) { if(data.code == 0){ createHtml(data.lineList) } }, fail: function (data) { // 此处放失败后执行的代码 } }); } //筛选列表 function createHtml(data){ var temp =""; for (var i = 0; i < data.length; i++) { temp +='
'+data[i].line+'
' } $(".xiala").html(temp); $(".xuanxiang").click(function(){ var line = $(this).text(); $("#text1").val(line); }) } //遍历列表 function createHtml_list(data){ var temp =""; for (var i = 0; i < data.length; i++) { temp += '' + '

'+data[i].lineName+" "+data[i].prodName+'

' + ''+data[i].startArea+'' + ''+data[i].endArea+'' + '' + '票种管理' + '' + '' } $("#list").html(temp); //temp=temp.replace('[操作]',str); } // 每页显示的数据个数 var pagesize = 10; var tttHTML = ''; window.onload = function() { var cur = ""; var currpage = getPar("currpage"); var text1 = ''; var data = '' if (!currpage) { cur = 1; text1 = $('#text1').val(); data = '{type:text1:' + text1 + ',currpage:' + cur + '}'; searchInfo(cur,text1); } else { cur = currpage; text1 = getPar('text1'); $('#text1').val(text1); data = '{type:"text1":' + text1 + 'currpage:' + cur + '}'; tttHTML = $('#list').html(); searchInfo(cur, text1); } } // 得到url上的参数 function getPar(par){ var local_url = document.location.href; local_url = decodeURI(local_url); var get = local_url.indexOf(par +"="); if(get == -1){ return false; } var get_par = local_url.slice(par.length + get + 1); var nextPar = get_par.indexOf("&"); if(nextPar != -1){ get_par = get_par.slice(0, nextPar); } return get_par; } //查询相关信息 function searchInfo(cur,text1){ if(!cur){ cur = 1; } if(!text1){ text1 = $('#text1').val(); } $.ajax({ url:'./st-xm/Model/line/getLineList.php', //请求地址 type: "get", //请求方式 // data: data, //请求参数 data:{ lineName:text1, currpage:cur, pagesize:pagesize }, async:false, dataType: "json", success: function (data) { if(data.code == 0){ console.log(data); var sum = data.totalNum; var tag = "test"; var sendurl = './query_line.html?text1='+text1; getPager(sendurl, sum, cur, pagesize,tag,'currpage'); createHtml_list(data.list); document.getElementById("sum").innerHTML = "共"+sum+"条数据"; }else if(data.code == -1){ alert('没有相关数据'); var sum = data.totalNum; var tag = "test"; var sendurl = './query_line.html?text1='+text1; getPager(sendurl, sum, cur, pagesize,tag,'currpage'); createHtml_list(data.list); document.getElementById("sum").innerHTML = "共0条数据"; } }, fail: function (data) { // 此处放失败后执行的代码 } }); if(cur!=1){ var text1 = getPar('text1'); $('#text1').val(text1); } }