自动补全输入框中的数据(jquery)

<input type= "text" id= "tt" style= "width:300px;" />
$( function (){
     $( "#tt" ).bigAutocomplete({data:[{title: "book" },
                                     {title: "blue" },
                                     {title: "fool" },
                                     {title: "bus" }]});
})

在文本输入框中输入字符,如果与["book","blue","fool","bus"] 里的数据模糊匹配,则自动补全下拉框显示匹配的数据。这里一次性把列表里所有的 数据通过data参数传入。


<input type= "text" id= "ff" style= "width:150px;" />
$( function (){
     $( "#ff" ).bigAutocomplete({width: "200px" ,
                                data:[{title: "book" },
                                      {title: "blue" },
                                      {title: "fool" },
                                      {title: "bus" }]});
})

在文本输入框中输入字符,如果与["book","blue","fool","bus"] 里的数据模糊匹配,则自动补全下拉框显示匹配的数据。这里一次性把列表里所有的 数据通过data参数传入。



<input type= "text" id= "qq" style= "width:320px;" />
$( function (){
     $( "#qq" ).bigAutocomplete({data:[{title: "book" ,result: "booooook" },
                                     {title: "blue" ,result: "bluuuuue" },
                                     {title: "fool" },
                                     {title: "bus" ,result:[1,2,3]}],
                              callback: function (data){
                                 alert(data);
                              }});  
})

 1、在文本输入框中输入字符,如果与["book","blue","fool","bus"] 里的数据模糊匹配,则自动补全下拉框显示匹配的数据。这里一次性把列表里所有的 数据通过data参数传入。
  2、回调函数返回选中行的数据(应用场景,选中行时文本框中是字符串,有时候需要对应记录的id或其他信息),比如选中book行,返回的是对象{title:"book",result:"booooook"}。




<input type= "text" id= "nn" style= "width:200px;" />
$( function (){
     var url_ = "ajax.php" ;
     $( "#nn" ).bigAutocomplete({url:url_});  
})

1、在文本输入框中输入字符,ajax从后台获取匹配数据,自动补全下拉框显示匹配的数据。
2、url可以带参数,比如http://localhost?id=1,则实际提交到后台的url为比如http://localhost?id=1&keyword=xx, keyword值为文本输入框键入的值,后台根据keyword过滤返回数据,数据的格式为json:{"data":[{"title":"ff","result":"gg"},{"title":"mm","result":"hh"}]},result属性可选。




<input type= "text" class= "batch-text" style= "width:200px;" />
<input type= "text" class= "batch-text" style= "width:200px;" />
$( function (){
     $( ".batch-text" ).bigAutocomplete({data:[{title: "book" },
                                     {title: "blue" },
                                     {title: "fool" },
                                     {title: "bus" }]});
})

1、批量给所有class为batch-text的文本框绑定相同的自动补全功能。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值