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

Can you implement association search in php?

藏色散人
Release: 2023-04-08 21:22:01
forward
2637 people have browsed it

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>
Copy after login

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!

Related labels:
php
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template