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