Home >Backend Development >PHP Tutorial >Can you implement association search in php?

Can you implement association search in php?

藏色散人
藏色散人forward
2020-06-13 14:42:492606browse

How to implement association search in php?

Lenovo search

1. The Lenovo function requires a database,

2. Each word Lenovo requires ajax to pass the value,

But then, we don’t use ajax here, because of the speed of ajax, so I use jquery.

Effect display:

Can you implement association search in php?

Code implementation:

When calling, jquery must first be introduced to achieve it

<meta charset="utf-8">
<input type="text"  value="" id="wd">
<div style=&#39;background: #e1e1e1;width:220px;display:none;&#39; id="rs">
    <ul>
 
    </ul>
</div>
<script src="jq.js"></script>
<script>
    $(function(){
        $("#wd").keyup(function(){
            var word=$(this).val();
            $.ajax({
                url:&#39;http://suggestion.baidu.com/su?wd=&#39;+word+&#39;&cb=showli&#39;,
                dataType:&#39;jsonp&#39;,
                jsonpCallback:&#39;showli&#39;,
                success:function(txt){
                    var arr=txt.s;
                    var li="";
                    $.each(arr,function(i,val){
                        li+="<li>"+val+"</li> ";
                    });
                    $("#rs ul").html(li);
                    $("#rs").slideDown(&#39;fast&#39;);
                    //鼠标经过元素的背景颜色改变
                    $("#rs ul li").bind(&#39;mouseenter&#39;,function(){$(this).css({&#39;background&#39;:&#39;yellow&#39;})});
                    $("#rs ul li").bind(&#39;mouseleave&#39;,function(){$(this).css({&#39;background&#39;:&#39;#e1e1e1&#39;})});
                    $("#rs ul li").bind(&#39;click&#39;,function(){
                        $("#wd").val($(this).html());
                        $("#rs").slideUp(&#39;fast&#39;);
                    });
            }})
    })
    })
</script>

The above is the detailed content of Can you implement association search in php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete