检索框文字联想功能

强调内容
会传递参数q到控制器

function hospital_query($q){
        $arr = array();
        $arr['suggestions'] = array();
        $arr['query'] = $q;
        $arr['data'] = array();
        if(empty($q)){
            return json_encode($arr);
        }else{
            $result = $this->db->query("SELECT  hospitalid,name FROM ".$this->table." WHERE parentid>-1 AND name LIKE  "."'%$q%'". " LIMIT 50");
            while($r = $this->db->fetch_array($result))
            {
                $arr['suggestions'][] = $r[name];
                $arr['data'][] = $r[hospitalid];
            }
            $this->db->free_result($result);
            return  json_encode($arr);
        }

引用块内容
这里面的三个加粗需要传递的参数,不可少

<style>
                        /*autocomplete*/
                        .autocomplete-w1 { position:absolute; top:0px; left:0px; margin:12px 0 0 4px;
                            /* IE6 fix: */ _background:none; _margin:0; }
                        .autocomplete {font:14px/1.5  Arial; border:1px solid #999; background:#FFF;
                            cursor:default; text-align:left; max-height:200px; overflow:auto; margin:-8px 6px 6px -5px;
                            /* IE6 specific: */ _height:200px;  _margin:0; _overflow-x:hidden; }
                        .autocomplete .selected { background:#F0F0F0; }
                        .autocomplete div { padding:1px 10px; white-space:nowrap; }
                        .autocomplete strong { font-weight:normal; color:#3399FF; }

                        /*autocomplete*/
                        .autocomplete-w1 {  position:absolute; top:0px; left:0px; margin:9px 0 0 0;}

                    </style>
                加上这个下拉列表样式

html

<span class="w76">
                        医院:<input name="keyword" id="keyword" type="text"  class="" autocomplete="off" >
                        <input id="cur_hospital_id" type="hidden"  name="info[bi_hospital_id]">
                    </span>
<script type="text/javascript" src="<?=PATH_JS?>/jquery.autocomplete-min.js"></script>
                    <script>
                        hospital = [];
                        //医院筛选
                        jQuery(function() {
                            var opt_q = {
                                serviceUrl: '?hospital_query',
                                minChars:1,
                                width: 532,
                                maxHeight:215,
                                deferRequestBy: 0,
                                noCache: false,
                                onSelect: function(value, data){
                                    document.getElementById('keyword').value = value;
                                    document.getElementById('cur_hospital_id').value = data;
                                }
                            }

                            $("#keyword").autocomplete(opt_q);
                        });

                    </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值