标准搜索案例

html

<div class="alert sb-alert alert-gray margin-left-50">
    <div class="row">
        <div class="col-lg-2">
            <span class="input-group input-group-sm">
                <span class="input-group-addon"><b>姓名:</b></span>
                <input type="text" class="form-control" id="name" value="{$name}" aria-describedby="base">
            </span>
        </div>

        <div class="col-lg-2">
            <span class="input-group input-group-sm">
                <span class="input-group-addon"><b>手机号:</b></span>
                <input type="text" class="form-control" id="telphone" value="{$telphone}" aria-describedby="base">
            </span>
        </div>


        <button type="button" class="btn btn-sm btn-primary" style="float: right; margin-right: 15px;" id="search">
            <i class="fa fa-search" aria-hidden="true"></i> 搜索
        </button>
    </div>

</div>

js

$("#search").on('click', function () {
    var pathname = window.location.pathname;

    var name = $("#name").val();
    var telphone = $("#telphone").val();

    var tail = '?search=1';

    if(name){
        tail += '&name='+name;
    }
    if(telphone){
        tail += '&telphone='+telphone;
    }
    window.location.href = "http://" + window.location.host + pathname + tail;
});

php

// search
$where = [];
if ($name = $_GET['name']) {
    $where['name'] = ['like',$name.'%'];
    $this->assign('name',$name);
}

if ($telphone = $_GET['telphone']) {
    $where['telphone'] = ['like',$telphone.'%'];
    $this->assign('telphone',$telphone);
}

$data_list=$women_get->where($where)->order('id desc')->limit($start.','.$step)->select();

干净利落

猜你喜欢

转载自www.cnblogs.com/jiqing9006/p/10451941.html