正文  软件开发 > PHP编程技术 >

ajax 实现输入提示效果,ajax实现提示效果

ajax 实现输入提示效果,ajax实现提示效果网站主页 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT...

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>
$("#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);

http://www.bkjia.com/PHPjc/1231449.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1231449.htmlTechArticleajax 实现输入提示效果,ajax实现提示效果 网站主页 !DOCTYPE htmlhtml lang="en"head meta charset="UTF-8" titleTitle/title style * { margin : 0px auto; padding : 0px...