用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - php代码库

JQuery 自动完成 ajax

2013-05-28 作者: 海大软件1102班举报

[php]代码库

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<title>jQuery Autocomplete Plugin</title>
<script type="text/javascript" src="../jquery_autocomplete/lib/jquery.js"></script>
<script type='text/javascript' src='../jquery_autocomplete/lib/jquery.bgiframe.min.js'></script>
<script type='text/javascript' src='../jquery_autocomplete/lib/jquery.ajaxQueue.js'></script>
<script type='text/javascript' src='../jquery_autocomplete/jquery.autocomplete.js'></script>
<script type='text/javascript' src='../jquery_autocomplete/lib/thickbox-compressed.js'></script>

<link rel="stylesheet" type="text/css" href="../jquery_autocomplete/jquery.autocomplete.css" />

    
<script type="text/javascript">
$().ready(function() {

    
    $("#suggest1").autocomplete("ajax.php", {
        minChars: 0,
        width: 230,
        highlight: false,
        scrollHeight: 300,
        matchContains: "word",   
        autoFill: false,   
        parse: function(data) {
            return $.map(eval(data), function(row) {
                return {
                    data: row,
                    value: row.name,
                    result: row.to
                }
            }); //对ajax页面传过来的数据进行json转码
        },
        formatItem: function(row, i, max) {
          return i + '/' + max + ':"' + row.name + '"[' + row.to + ']';
          },
        formatMatch: function(row, i, max) {
         return row.name + row.to;
        },
         formatResult: function(row) {
          return row.to;
        }
    }).result(function(event, row, formatted) {
                    return row.to;
             });
    

});


</script>
    
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<body>

<h1 id="banner"><a href="http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/">jQuery Autocomplete Plugin</a> local deomo</h1>

<div id="content">
    
    <form>
        <p>
            <label>选择客户:</label>
            <input type="text" id="suggest1" size="30px"/>
            
        </p>
        
    </form>
</div>

</body>
</html>

 index结束

 

ajax.php

 

<?php

$conn = @mysql_connect("localhost", "root", "") or die("Failed!");
mysql_select_db("jquery_test", $conn);
mysql_query("set names 'utf8'");

$q = $_GET["q"];
if (!$q)
    return;

$items = array();
$sql1  = mysql_query("select `CLIENT_N_SHORT`,`CLIENT_NAME` from `client`");
while ($row = mysql_fetch_array($sql1)) {
    $key   = $row['CLIENT_N_SHORT'];
    $value = $row['CLIENT_NAME'];
    
    if (strpos($value, $q) !== false) {
        array_push($items, array(
            "name" => urlencode($key),
            "to" => urlencode($value)
        ));
        
        //防止json中文乱码 因此转码
        
    }
}
//print_r($items);
//exit();
//echo "<hr>";

echo urldecode(json_encode($items));
?>


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...