ajax实现输入提示效果
本文实例为大家分享了ajax实现输入提示效果的具体代码,供大家参考,具体内容如下
网站主页
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> *{ margin:0px auto; padding:0px; } .l{ height:50px; width:198px; border-bottom:1px solid black; text-align: center; line-height:40px; vertical-align: middle; } </style> <script src="../wenjian/jquery-2.2.3.min.js"></script> </head> <body> <div style="height: 50px;width: 200px"><input type="text" id="name" style="width: 198px;height: 48px;"></div> <div id="list" style="height: 500px;width: 200px;border: 1px solid black"> <!--<div id="l">zhongguo</div>--> </div> </body> </html> <script> $("#name").keyup(function () { var n = $("#name").val(); if (n != ""){ $.ajax({ url:'ltchuli.php', data:{n:n}, type:'post', // dataType:'text', dataType:'json', success:function (data) { //text写法 // var s = data.split("|"); // var str = ""; // for (var i=0;i<s.length;i++) // { // str = str + "<div class='l'>" +s[i] +"</div>"; // } // $("#list").html(str); //json写法 for (var i in data){ $("#list").append("<div class='l'>" +data[i] +"</div>"); } } }); }else { $("#list").html(""); } }) </script>
处理页面
<?php /** * Created by fcc * User: Administrator * Date: 2017/10/30 * Time: 9:52 */ $n = $_POST['n']; require_once "../wenjian/DBDA.class.php"; $db = new DBDA(); $obj = "select region_name from region WHERE region_name LIKE '%{$n}%' "; $data = $db->Query($obj); //echo $data; echo json_encode($data);
相关推荐
时光如瑾雨微凉 2020-07-19
ppsurcao 2020-06-14
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
Richardxx 2020-11-09
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03
TONIYH 2020-07-22
83510998 2020-07-18
坚持着执着 2020-07-16
jiaguoquan00 2020-07-07
李永毅 2020-07-05