Quote: 引用 2 楼 Return_false 的回复:

完全不会,悲剧啊

解决方案 »

  1.   

    正解   
    需要 增加input 的onchange事件 ,就是比如你输入一个"北" , 输入框内容发生变化 ,触发onchange事件 在该事件处理程序中通过ajax获取数据库与"北"相关的城市地址列表,生成下拉列表让你选择 需要使用如Jquery AutoComplete控件,实现较为简单
      

  2.   

    实现简单么,可是我完全不会js,能不能帮忙写个demo呢,不甚感激
      

  3.   

    你去下一个 里面都有demo的 也有函数的介绍api手册 对着看就好了
      

  4.   

    正解   
    实现简单么,可是我完全不会js,能不能帮忙写个demo呢,不甚感激 ,还有我自己没有数据库,数据也和天气网一样从别处获取。
      

  5.   

    示例仅供参考<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>autocomplete测试</title><link rel="stylesheet" type="text/css" href="jquery-ui-1.10.4.custom/css/ui-lightness/jquery-ui-1.10.4.custom.min.css" />
    <style>img{width:30px;height:30px;}</style>
    <script src="jquery-ui-1.10.4.custom/js/jquery-1.10.2.js"></script>
    <script src="jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.min.js"></script>
    </head><body>
    <input type="text" id="autocompleteTest" autocomplete="off" name="q" value="autocomplete测试" onfocus="if(this.value=='autocomplete测试'){this.value='';}" onblur="if(this.value=='') {this.value = 'autocomplete测试';}" class="ui-autocomplete-input">
    <script type="text/javascript">
    var json=[{label:"aaa",pictureurl:"http://www.baidu.com/img/bdlogo.gif",url:"http://www.baidu.com"},{label:"bbbbb",pictureurl:"http://i1.sinaimg.cn/dy/deco/2013/0329/logo/LOGO_1x.png",url:"http://www.sina.com"}];
    $(function () {
    $('#autocompleteTest').autocomplete({
    delay: 500,
    minLength: 1,
    source: json,//这里为了测试,直接定义了一个json对象,实际应用中通常是一个url地址
    select: function( event, ui ) {
    $("#autocompleteTest").val(ui.item.label);
    //location=(ui.item.url);
    return false;
    }
    }).data("ui-autocomplete")._renderItem = function( ul, item ) {
    var t = item.label;

    return $("<li></li>")
    .data("item.autocomplete", item)
    .append("<a><img src='" + item.pictureurl + "'>" + t + "</a>"
    ).appendTo(ul);
    };
    });</script>
    </body>
    </html>