zoukankan      html  css  js  c++  java
  • ajax实时获取下拉数据

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    ajax实时获取下拉数据</pre>
    <style><!--
    .input_s{ position:relative}
    .input_s ul{ list-style:none; margin:0; padding:0; 200px; border:1px solid #ccc; border-bottom:none}
    .input_s ul li{ border-bottom:1px solid #ccc}
    .input_s ul li:hover{ color:#fff; background:#000}
    --></style>
    <pre></pre>
    <div class="input_s"><input class="tla" id="tla" style=" 500px;" type="text" name="tla" />
    </div>
    <pre>
    <script type="text/javascript">// <![CDATA[
    var funjieliu = function(fn, delay){//函数节流  add by shanmao 2013 - 1 - 18
        var timer = null;
        return function(){
            var context = this, args = arguments;
            clearTimeout(timer);
            timer = setTimeout(function(){
                fn.apply(context, args);
            }, delay);
        };
     };
    document.getElementById("tla").onkeyup=funjieliu(function(){//键盘按下的时候
        var tla = $("#tla").val();
        if(tla){
            $.post("/cityosweb/default.php/shanmao/input_xiala",{tla:tla},function(data){
                if(data.status==1){
                    $(".inul").html("");
                    $.each(data.data,function(index,val){
                        $(".inul").append("
        <li>"+val.username+"</li>
     
    ");
                        });
                }
                },"json");
            }
        },500);
    $(function(){
        $(".inul li").live("click",function(){
            var thval = $(this).html();
            var tla = $("#tla").val();
            var regexp = new RegExp(",");
            if(regexp.test(tla)){//如果input有值(",")则加上input里面的值
            $("#tla").val(tla+thval+",");
                }else{
            $("#tla").val(thval+",");
                    }
            $(".inul").html("");
            $("#tla").focus();
            });
        });
    // ]]></script>
     
    function input_xiala(){
        $input = new input();
        $tval = $input->post('tla');
        $u = M('User');
        if(strpos($tval,",")){//检查是否带有","
            $val = explode(",",$tval);//拆分成数组
            $tval = end($val);//数组的最后一个值
            }
        $re = $u->field('username,email')->where("username like '$tval%'")->limit(10)->select();
        $this->ajaxReturn($re,'success',1);
        }
  • 相关阅读:
    mysql source 乱码
    php5.6.11 openssl安装
    python threading模块的Lock和RLock区别
    python多线程一些知识点梳理
    多核处理器中进程和线程是如何一起工作的?
    IO是否会一直占用CPU?(转)
    Python TypeError: __init__() got multiple values for argument 'master'(转)
    Jquery中.bind()、.live()、.delegate()和.on()之间的区别详解(转)
    浏览器环境下JavaScript脚本加载与执行探析之代码执行顺序(转)
    为什么有的网页右击没有出现审查元素
  • 原文地址:https://www.cnblogs.com/sanwenyu/p/4549367.html
Copyright © 2011-2022 走看看