JQuery UI Autocomplete
来源:互联网 发布:阿里云短信接口 php 编辑:程序博客网 时间:2024/05/21 17:37
<!doctype html><html lang="en"><head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>jQuery UI Autocomplete - Remote datasource</title> <link rel="stylesheet" href="http://code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css"> <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css"> <style> .ui-autocomplete-loading { background: white url("../images/ui-anim_basic_16x16.gif") right center no-repeat; } </style> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script> <script> $(function () { function log(message) { $("<div>").text(message).prependTo("#log"); $("#log").scrollTop(0); } $("#birds").autocomplete({ source: "../handler/CommonHandler.ashx?", minLength: 0, select: function (event, ui) { log(ui.item ? "Selected value = " + ui.item.value + ",id = " + ui.item.id : "Nothing selected, input was " + this.value); event.preventDefault(); $("#birds").val(ui.item.label); }, focus: function (event, ui) { event.preventDefault(); $("#birds").val(ui.item.label); } }); }); </script></head><body> <div class="ui-widget"> <label for="birds">Birds: </label> <input id="birds"> </div> <div class="ui-widget" style="margin-top:2em; font-family:Arial"> Result:<div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div> </div></body></html>
source:是远程请求地址,请求返回的格式如下:
当你输入关键词时,插件会根据你设置的minLength的限制开始向URL请求,注意URL中会自动添加term参数,如下:
http://localhost:52865/handler/CommonHandler.ashx?&term=k
当你进行上下选择的时候,默认会选择value到input输入框,在select事件中,添加如下代码:
select: function (event, ui) { event.preventDefault(); $("#birds").val(ui.item.label); }, focus: function (event, ui) { event.preventDefault(); $("#birds").val(ui.item.label); }
参考链接:
http://stackoverflow.com/questions/7642855/autocomplete-applying-value-not-label-to-textbox
http://api.jqueryui.com/autocomplete/
0 0
- JQUERY UI autocomplete
- jquery ui autocomplete
- 使用 jQuery UI AutoComplete
- jQuery UI AutoComplete
- jQuery UI Autocomplete 体验
- jQuery UI Autocomplete 体验
- jquery ui autocomplete实例
- JQuery UI Autocomplete
- jQuery UI Autocomplete
- Jquery UI autoComplete 设置max
- jquery-ui-autocomplete的使用
- jQuery UI Autocomplete 体验分享
- jquery-ui-autocomplete的使用
- jquery ui autocomplete使用示例
- jQuery UI Autocomplete 事件API
- jquery-ui-1.11 autocomplete使用
- jquery UI Autocomplete 自动提示
- jQuery UI Autocomplete 事件API
- “人生没有一桩幸福不要付代价的。东边占了便宜,西边就得吃亏些。”--《傅雷家书》
- Mybatis Generator最完整配置详解
- 使用Crashlytics收集iOS崩溃报告
- group by分组内排序,取其中一条
- 软件开发者的精力管理(一)
- JQuery UI Autocomplete
- A Java Runtime Environment (JRE) or Java Development Kit (JDK)
- iOS动画——按钮弹窗
- powerdesinger中修改name时code不随着变化的配置
- 弹性布局基础讲解与高效应用
- 课工场官网注册UID获取免费学习视频课
- RxJava与网络相关的操作符(range/defer/retry/repeat/timer/delay/interval/BehaviorSubject/zip)
- Vivado SPI Flash程序下载
- iOS App上架流程(细版)