Heim > php教程 > php手册 > Wenn die tp5-Seite ausgegeben wird, wird nach der Suche zur nächsten Seite gesprungen

Wenn die tp5-Seite ausgegeben wird, wird nach der Suche zur nächsten Seite gesprungen

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-10-08 16:04:41
Original
2198 Leute haben es durchsucht

Wenn die tp5-Seite ausgegeben wird und die Suchfunktion zur nächsten Seite springt und keine Verarbeitung erfolgt, werden die auf der zweiten Seite ausgegebenen Originaldaten zurückgegeben. Um sicherzustellen, dass die gesuchten Daten beim Springen zur nächsten Seite ausgegeben werden, führen Sie die folgende Verarbeitung durch.

(Sie müssen es entsprechend Ihrem eigenen Suchfeld ändern)

Fügen Sie im js-Code der Seite Parameter zur Adressleiste hinzu, sodass Sie auf die Suchschaltfläche klicken können, um die Suchbedingungen über die Adressleiste im Hintergrund abzurufen.

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

Durchsuchen Sie den HTML-Code einiger Seiten

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

Controller-Hauptcode

<span style="color: #0000ff;">if </span>(empty(input('get.'<span style="color: #000000;">))) {
  $page </span>= NewsModel::where('isdelete',1)->order('id desc')->paginate(8<span style="color: #000000;">);
  $</span><span style="color: #0000ff;">this</span>->assign('list'<span style="color: #000000;">,$page);
</span><span style="color: #0000ff;">  return</span> $<span style="color: #0000ff;">this</span>-><span style="color: #000000;">fetch();
} </span><span style="color: #0000ff;">else </span><span style="color: #000000;">{
  $shop_id</span>=input('get.shop_id'<span style="color: #000000;">);
  $key</span>=input('get.key'<span style="color: #000000;">);
</span><span style="color: #0000ff;">  if </span>($shop_id=='all' && $key != ''<span style="color: #000000;">) {
    $page</span>=NewsModel::where(['title'=>['like',"%$key%"],'isdelete'=>['eq',1]])->order('id desc')->paginate(8,<span style="color: #0000ff;">false</span><span style="color: #000000;">,[
</span>    'query' => ['shop_id' => $shop_id,'key' => $key] <span style="color: #008000;">//</span><span style="color: #008000;">url额外参数</span>
<span style="color: #000000;">    ]);
  } elseif ($shop_id </span>!= 'all' && $key != ''<span style="color: #000000;">) {
    $page</span>=NewsModel::where(['title'=>['like',"%$key%"],'shop_id'=>['eq',$shop_id],'isdelete'=>['eq',1]])->order('id desc')->paginate(8,<span style="color: #0000ff;">false</span><span style="color: #000000;">,[
</span>    'query' => ['shop_id' => $shop_id,'key' =><span style="color: #000000;"> $key]
    ]);
  } elseif ($shop_id </span>!= 'all' && $key == ''<span style="color: #000000;">) {
    $page</span>=NewsModel::where(['shop_id'=>['eq',$shop_id],'isdelete'=>['eq',1]])->order('id desc')->paginate(8,<span style="color: #0000ff;">false</span><span style="color: #000000;">,[
</span>    'query' => ['shop_id' => $shop_id,'key' =><span style="color: #000000;"> $key]
    ]);
  } </span><span style="color: #0000ff;">else </span><span style="color: #000000;">{
    $page</span>=NewsModel::where('isdelete',1)->order('id desc')->paginate(8,<span style="color: #0000ff;">false</span><span style="color: #000000;">,[
</span>    'query' => ['shop_id' => $shop_id,'key' =><span style="color: #000000;"> $key]
    ]);
  }
  $</span><span style="color: #0000ff;">this</span>->assign('list'<span style="color: #000000;">,$page);
</span><span style="color: #0000ff;">  return</span> $<span style="color: #0000ff;">this</span>-><span style="color: #000000;">fetch();
}</span>
Nach dem Login kopieren

Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage