jQuery技术

autocomplete学习一:用法示例

字号+ 作者:H5之家 来源:H5之家 2017-05-28 08:03 我要评论( )

jquery-autocomplete学习一:用法示例_灵灵_新浪博客,灵灵,

jquery-autocomplete学习

1.功能:

   实现根据关键字进行搜索功能,让一个input或textarea有autocomplete功能,类似百度和google的自动搜索功能;

2.代码示例:

 

(1)引入js和css文件

<script src="./jquery-1.3.2.js" type="text/javascript"></script>

<script src="./jquery.autocomplete.js" type="text/javascript"></script>

<link href="./jquery.autocomplete.css" />

 

(2)JS代码:

     $("#webServer").autocomplete({
 source: function(request, response) {
 $.ajax({
  url: "servlet/uiWebServer?keyValue="+request.term,
  type : "GET",
  dataType: "json",
  success: function(data) {
   response($.map(data.list, function(item) {
    return {
     label: item.sscWebServerAddress,
     value: item.sscWebServerAddress,
     sscWebServerId: item.sscWebServerId
    };
   }));
  },
  error: function(request,textStatus, errorThrown) {alert('fail');alert(errorThrown);}
 });
 },
});

 

(3)html代码:

 <input type="text" >

 

(4)数据格式:

{"list":[{"sscWebServerAddress":"127.0.0.1:8080","sscWebServerId":"10148","createdByUserLogin":null,"lastUpdatedByUserLogin":null,"createdStamp":"","lastUpdatedStamp":""},{"sscWebServerAddress":"127.0.0.1%3A18080","sscWebServerId":"10145","createdByUserLogin":null,"lastUpdatedByUserLogin":null,"createdStamp":"","lastUpdatedStamp":""},{"sscWebServerAddress":"127.0.0.1:18080","sscWebServerId":"10080","createdByUserLogin":null,"lastUpdatedByUserLogin":null,"createdStamp":"","lastUpdatedStamp":""}]

 

友情链接:

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
网友点评