jQuery和Grails的/ HTML - 使文本字段完整的文本像谷歌做 [英] jQuery and Grails/HTML - Make text field complete text like Google does

查看:127
本文介绍了jQuery和Grails的/ HTML - 使文本字段完整的文本像谷歌做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让某些领域在我的网页,以显示我像就像谷歌可能整理句子的列表呢。

I wanna make certain fields in my page to show me like a list of possible finishing sentences just like Google does.

我觉得这是通过jQuery做,但我不知道。

I think this is done via jQuery, but I'm not sure.

文本字段命名的商品。

比方说,我写的秘书长和列表,数组或DB我有一般商品,我应该告诉我一般商品的文本框下。

Let's say I write General and in the list, array, or DB I have General Commodity I should show me General Commodity under the textfield.

在此先感谢!

------- -------更新

-------UPDATE-------

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js">
var data = "General Commodity,General Store,General Custer,General Mills".split(",");

    $("#Ccommodity").autocomplete({
            source: data
        });
</script>

当我去Ccommodity输入文本框我写G和什么也没发生,也许我有一些语法错误在那里。

When I go to the Ccommodity input textfield I write G and nothing happens, maybe I have some syntax error there.

感谢您的帮助。

推荐答案

您可能会想看看进入 jQueryUI的自动完成构件。它提供的建议名单的几种方法,并有几乎肯定会成为东西在里面,会为你工作。

You will probably want to look into the jQueryUI Autocomplete widget. It has several ways of providing lists of suggestions, and there will almost certainly be something in there that will work for you.

下面是一个非常基本的演示: http://jsfiddle.net/QU9st/

Here's a very basic demo: http://jsfiddle.net/QU9st/

下面是源:

$(function() {
    var data = "General Commodity,General Store,General Custer,General Mills".split(",");
    $("#commodity").autocomplete({
            source: data
        });
});

这只是演示使用静态字符串数组作为数据源,但你也可以使用远程数据源,在格式,如JSON或XML。

That demo simply uses a static string array as the datasource, but you can also use remote datasources, in formats like JSON or XML.

要得到它,就放弃这一某处你的&LT; HEAD&GT; 标签:

To get it, just drop this somewhere in your <head> tag:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"></script>

当然,你还需要包括jQuery的:

Of course, you will also need to include jQuery:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

这篇关于jQuery和Grails的/ HTML - 使文本字段完整的文本像谷歌做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆