Magic
早速、コードについて説明します。
フロントデスク:
<br />function on_post_form(){<br /> var f = document.post_myform;<br /> var s_paramName = document.getElementById("select_paramName").value;<br /> f.action = "__APP__/index/select_infomessage-s_paramName-"+encodeURIComponent(s_paramName)+".html";<br /> f.submit();<br />}<br /><input name="select_paramName" class="KeyWord" id="select_paramName" size="20" maxlength="30" type="text"><br /><div id="searchresult" style="display: none;"></div><br />
<br />$(document).ready(function(){<br /> $('#select_paramName').keyup(function(){ //输入框的id为search,这里监听输入框的keyup事件<br /> $.ajax({<br /> type:"GET", //AJAX提交方式为GET提交<br /> url:"__APP__/index/get_search_showdiv", //处理页的URL地址<br /> data:"s_Name="+encodeURIComponent($('#select_paramName').val()), //要传递的参数<br /> success:function(data){ //成功后执行的方法<br /> if(data != ""){<br /> var ss;<br /> ss = data.split("@"); //分割返回的字符串<br /> var layer;<br /> layer = "<table>"; //创建一个table<br /> for(var i=0;i<ss.length-1;i++){<br /> layer += "<tr><td class='line'>"+ss[i]+"</td></tr>";<br /> }<br /> layer += "</table>";<br /> $('#searchresult').empty(); //先清空#searchresult下的所有子元素<br /> $('#searchresult').append(layer);//将刚才创建的table插入到#searchresult内<br /> $("#searchresult").css("display", "");<br /> $('.line').hover(function(){ //监听提示框的鼠标悬停事件<br /> $(this).addClass("hover"); <br /> },function(){<br /> $(this).removeClass("hover");<br /> });<br /> $('.line').click(function(){ //监听提示框的鼠标单击事件<br /> $('#select_paramName').val($(this).text());<br /> $("#searchresult").css("display", "none"); <br /> ChangeCoords();<br /> });<br /> }else{<br /> $('#searchresult').empty();<br /> }<br /> }<br /> });<br /> });<br />});<br />
<br />public function get_search_showdiv()<br /> {<br /> //urlencode urldecode 文本框自动提示<br /> $keyword = urldecode($_GET['s_Name']);<br /> $condition = "f_hotname like '%".$keyword."%'";<br /> $info=$this->model->table('forest')->field('f_hotname')->where($condition)->order('f_id desc')->limit(5)->select();<br /> if($keyword !=""){<br /> foreach($info as $vo) <br /> { <br /> echo $vo['f_hotname'].'@'; <br /> } <br /> }else{<br /> <br /> echo "";<br /> }<br /> }<br />