zoukankan      html  css  js  c++  java
  • tp5页面输出时,搜索后跳转下一页的处理

    tp5页面输出时,搜索功能在跳转下一页时,如果不做任何处理,会返回原有是第二页输出的数据。为了保证跳转下一页时输出的是搜索到的数据,做以下处理。

    (要根据自己的搜索字段进行适当修改)

    页面js代码,给地址栏加上参数,以便于点击搜索按钮后台通过地址栏得到搜索条件。

    $(document).ready(function(){
         //点击搜索按钮执行搜索  $(
    "#search").click(function() { var form = $('#form'); var url = form.attr('action'); var query = $('.key').serialize(); query = query.replace(/(&|^)(w*?d*?-*?_*?)*?=?((?=&)|(?=$))/g, ''); query = query.replace(/^&/g, ''); if (url.indexOf('?') > 0) { url += '&' + query; } else { url += '?' + query; } form.attr('action',url); }); //回车搜索 $(".search-form").keyup(function(e) { if (e.keyCode === 13) { $(".search").click(); return false; } });
        //设定input框的值,保留搜索条件,setValue的方法参照http://www.cnblogs.com/xiaopiyuanzi/p/5920864.html setValue(
    'shop_id', "{:input('get.shop_id')}"); setValue('key', "{:input('get.key')}"); })

     搜索部分页面html代码

    <div class="search search-form" style="background: #e0e0e0;margin-bottom: 10px">
        <form action="{:url('news')}" id="form" method="post"
            <table border="0" style="height: 50px;font-size: 15px;color: black;" cellpadding="5" width="35%">
                <tr>
                    <td>商品类:
                        <select name="shop_id" class="key">
                            <option value="all">全部</option>
                            {volist name='li' id='k'}
                            <option value="{$k.id}">{$k.name}</option>
                            {/volist}
                        </select>
                    </td>
                    <td>标题:<input type="text" name="key" class="key" class="inpMain" placeholder="新闻标题或标题包含字"></td>
                    <td><input type="submit" id="search" class="btn" value="搜索" /></td>
                </tr>
            </table>
        </form>
    </div>                            

    控制器主要代码

    if (empty(input('get.'))) {
      $page = NewsModel::where('isdelete',1)->order('id desc')->paginate(8);
      $this->assign('list',$page);
      return $this->fetch();
    } else {
      $shop_id=input('get.shop_id');
      $key=input('get.key');
      if ($shop_id=='all' && $key != '') {
        $page=NewsModel::where(['title'=>['like',"%$key%"],'isdelete'=>['eq',1]])->order('id desc')->paginate(8,false,[
        'query' => ['shop_id' => $shop_id,'key' => $key] //url额外参数
        ]);
      } elseif ($shop_id != 'all' && $key != '') {
        $page=NewsModel::where(['title'=>['like',"%$key%"],'shop_id'=>['eq',$shop_id],'isdelete'=>['eq',1]])->order('id desc')->paginate(8,false,[
        'query' => ['shop_id' => $shop_id,'key' => $key]
        ]);
      } elseif ($shop_id != 'all' && $key == '') {
        $page=NewsModel::where(['shop_id'=>['eq',$shop_id],'isdelete'=>['eq',1]])->order('id desc')->paginate(8,false,[
        'query' => ['shop_id' => $shop_id,'key' => $key]
        ]);
      } else {
        $page=NewsModel::where('isdelete',1)->order('id desc')->paginate(8,false,[
        'query' => ['shop_id' => $shop_id,'key' => $key]
        ]);
      }
      $this->assign('list',$page);
      return $this->fetch();
    }
  • 相关阅读:
    Python---HTML常用标签
    Python---进阶---Tkinter---game
    工程师的URL大全
    docker安装小笔记
    SQL server查询语句
    非常好用的sersync同步工具
    运维自动化的标准
    使用ansible实现轻量级的批量主机管理
    emos邮件系统的web密码修改方法
    Linux 之 rsyslog+mysql+LogAnalyzer 日志收集系统
  • 原文地址:https://www.cnblogs.com/xiaopiyuanzi/p/5922886.html
Copyright © 2011-2022 走看看