Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery分页结果页面_Javascript_Jquery - Fatal编程技术网

Javascript jQuery分页结果页面

Javascript jQuery分页结果页面,javascript,jquery,Javascript,Jquery,我创建了一个GoogleMaps商店定位器,并使用jquery分页来显示每页仅5个结果。它起作用了。唯一的问题是,每次我点击search,它都会重复分页 代码: function paginate(){ var page = 1; var itemsPerPage = 4; var prev = "Previous Results"; var next = "More Results"; var $entries = $("#entries"); var $list = $entries.c

我创建了一个GoogleMaps商店定位器,并使用jquery分页来显示每页仅5个结果。它起作用了。唯一的问题是,每次我点击search,它都会重复分页

代码:

function paginate(){
var page = 1;
var itemsPerPage = 4;
var prev = "Previous Results";
var next = "More Results";

var $entries = $("#entries");
var $list = $entries.children("ul:first");
$list.children().eq(itemsPerPage).nextAll().andSelf().hide();

var $pagination = $("<ul class='pagination'></ul>").each(function () {
   var itemsTotal = $list.children().size();
   var pages = Math.ceil(itemsTotal / itemsPerPage);
$(this).append("<span class='endline'></span>");
   $(this).append("<li class='prev'>" + prev + "</li>");
   $(this).append("<li class='more'>" + next + "</li>");
}).appendTo($entries);
$pagination.children("li:first").hide();
$pagination.children().click(function () {

   if ($(this).text() == prev)
       page = page - 1;
   else if ($(this).text() == next)
       page = page + 1;

   var firstToShow = (page - 1) * itemsPerPage;
   var lastToShow = page * itemsPerPage;
   $list.children().hide().slice(firstToShow, lastToShow).slideDown('slow');

   if (page == 1)
       $(this).parent().find("li:first").hide();
   else
       $(this).parent().find("li:first").show();
   if (page == Math.ceil($list.children().size() / itemsPerPage))
       $(this).parent().find("li:last").hide();
   else
       $(this).parent().find("li:last").show();
});
}
函数paginate(){
var-page=1;
var itemsPerPage=4;
var prev=“以前的结果”;
var next=“更多结果”;
var$分录=$(“#分录”);
var$list=$entries.children(“ul:first”);
$list.children().eq(itemsPerPage.nextAll().andSelf().hide();
var$pagination=$(“
    ”)。每个(函数(){ var itemsTotal=$list.children().size(); var pages=Math.ceil(itemsTotal/itemsPerPage); $(此)。追加(“”); $(此)。追加(“”; $(this.append(“
  • ”+next+”
  • ”); }).附于($条目); $pagination.children(“li:first”).hide(); $pagination.children()。单击(函数(){ if($(this).text()==prev) 第页=第1页; else if($(this).text()==next) 页码=页码+1; var firstToShow=(第1页)*itemsPerPage; var lastToShow=page*itemsPerPage; $list.children().hide().slice(firstToShow,lastToShow).slideDown('slow'); 如果(第==1页) $(this.parent().find(“li:first”).hide(); 其他的 $(this.parent().find(“li:first”).show(); if(page==Math.ceil($list.children().size()/itemsPerPage)) $(this.parent().find(“li:last”).hide(); 其他的 $(this.parent().find(“li:last”).show(); }); }
    然后在我的谷歌地图javascript中(代码取自):

    函数搜索位置近(中){
    var radius=document.getElementById('radiusSelect')。值;
    var searchUrl='genxml.php?lat='+center.lat()+'&lng='+center.lng()+'&radius='+radius;
    GDownloadUrl(搜索URL、函数(数据){
    var xml=GXml.parse(数据);
    var markers=xml.documentElement.getElementsByTagName('marker');
    map.clearOverlays();
    var sidebar=document.getElementById('sidebar');
    sidebar.innerHTML='';
    如果(markers.length==0){
    sidebar.innerHTML='

    未找到任何结果。

    '; 地图设置中心(新格拉特林(40,-100),4); 返回; } var bounds=新的glatlngbunds(); 对于(var i=0;i
    html:

    
    
    • 所有条目
    • 所有条目
    然后是分页
      按钮上有:

      <input type="button" onclick="searchLocations()" class="submit" value="Search"/>
      
      
      
      这个功能是:

      function searchLocations() {
      var address = document.getElementById('addressInput').value;
      geocoder.getLatLng(address, function(latlng) {
      if (!latlng) {
      sidebar.innerHTML = '<p class="caption"><b>No results found.</b><br><br>Please try your search again. Make sure to enter a single city, state, or zip code.</p>';
       } else {
         searchLocationsNear(latlng);
         filter();
       }
      });
      }
      
      函数searchLocations(){
      var address=document.getElementById('addressInput')。值;
      geocoder.getLatLng(地址、功能(latlng){
      如果(!latlng){
      sidebar.innerHTML='

      未找到任何结果。

      请重试搜索。请确保输入一个城市、州或邮政编码。

      ; }否则{ 搜索位置导航(latlng); 过滤器(); } }); }
      paginate()
      函数中重新创建任何现有分页之前,添加以下行以删除它:

      $(".pagination").remove();
      
      因此,你最终会:

      $(".pagination").remove();
      var $pagination = $("<ul class='pagination'></ul>").each(function () { 
         ...
      }).appendTo($entries); 
      
      $(“.pagination”).remove();
      var$pagination=$(“
        ”)。每个(函数(){ ... }).附于($条目);
        你的标记看起来像什么,或者你用id=“entries”设置了哪个元素?哎呀,我就知道我忘了一些东西>
        • 所有的条目
        • 所有的条目
        • 等等
        然后是分页
          将其添加到其余部分抱歉:XDo我是否删除了整个函数?哦,不,不,它实际上不在标记中,我只是在显示页面呈现后显示的位置。抱歉,我没有意识到这是呈现的标记-我现在已修改,它应该可以解决您的问题。
          $(".pagination").remove();
          
          $(".pagination").remove();
          var $pagination = $("<ul class='pagination'></ul>").each(function () { 
             ...
          }).appendTo($entries);