doudu2591
2017-02-02 15:34
浏览 64
已采纳

如何在服务器端调用分页停止页面重新加载?php

I am implementing pagination where on click i change the style from list view to grid but when i click the next page button or link it is actually redirects me back to again list view button again

$pagination.= "<li><a href='{$url}page={$counter}'>{$counter}</a></li>"; 

now i want to keep my style same as it was if i have clicked grid so on next page click it remain a grid not turn to list as page load again fetch new record it change my style

   $(document).ready(function () {    
  var elem=$('#container ul');      
    $('#viewcontrols a').on('click',function(e) {
    if ($(this).hasClass('gridview')) {
        elem.fadeOut(1000, function () {
            $('#container ul').removeClass('list').addClass('grid');
            $('#viewcontrols').removeClass('view-controls-list').addClass('view-controls-grid');
            //$('#viewcontrols .gridview').addClass('active');
            $('#viewcontrols .listview').removeClass('active');
            elem.fadeIn(1000);
        });                     
    }
    else if($(this).hasClass('listview')) {
        elem.fadeOut(1000, function () {
            $('#container ul').removeClass('grid').addClass('list');
            $('#viewcontrols').removeClass('view-controls-grid').addClass('view-controls-list');
            $('#viewcontrols .gridview').removeClass('active');
            //$('#viewcontrols .listview').addClass('active');
            elem.fadeIn(1000);
            });                                 
        }
    });
  });
  </script>

so is there any why like i declare a such a variable that donot destroy even on page load and manage style or how to do that ?

 var elem=$('#container ul');   

图片转代码服务由CSDN问答提供 功能建议

我正在实现分页,点击我将样式从列表视图更改为网格,但是当我单击下一页按钮时 或链接它实际上将我重新定向回再次列表视图按钮

  $ pagination。=“&lt; li&gt;&lt; a href ='{$ url} page = {  $计数器}'&GT; {$计数器}&LT; / A&GT;&LT; /锂&gt;“中;  
   
 
 

现在我想保持我的风格与我点击网格相同,所以在下一页点击它仍然是一个网格不再转向列表再次作为页面加载 获取新记录它改变了我的风格

  $(document).ready(function(){
 var elem = $('#container ul'); 
 $(  '#viewcontrols a')。on('click',function(e){
 if($(this).hasClass('gridview')){
 elem.fadeOut(1000,function(){
 $  ('#container ul')。removeClass('list')。addClass('grid'); 
 $('#viewcontrols')。removeClass('view-controls-list')。addClass('view-controls-  grid'); 
 // $('#viewcontrols .gridview')。addClass('active'); 
 $('#viewcontrols .listview')。removeClass('active'); 
 elem.fadeIn(  1000); 
}); 
} 
否则if($(this).hasClass('listview')){
 elem.fadeOut(1000,function(){
 $('#container ul')  ).removeClass('grid')。addClass('list'); 
 $('#viewcontrols')。removeClass(  'view-controls-grid')。addClass('view-controls-list'); 
 $('#viewcontrols .gridview')。removeClass('active'); 
 // $('#viewcontrols .listview  ')。addClass('active'); 
 elem.fadeIn(1000); 
});  
} 
}); 
}); 
&lt; / script&gt; 
   
 
 

所以有什么为什么我声明这样一个变量 甚至在页面加载和管理风格或如何做到这一点时不会破坏?

  var elem = $('#container ul');  
   
 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doumengxue7371 2017-02-02 15:41
    已采纳

    You could save the selected style in the localStorage. On page load you can load the style from the localStorage again.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • douliang1891 2017-02-02 15:42

    Something like:

    <li id="pagination_link"><a href= . . . ></li>
    

    Then in JS, something like this:

    $('#pagination_link').on('click', 'a href', function(e){
      e.preventDefault();
    });
    

    Or if I remember correctly:

    $('#pagination_link').on('click', 'a href', function(e){
      return false;
    });
    

    Should stop the link redirecting. You just need to override the default behavior of a href.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题