大佬教程收集整理的这篇文章主要介绍了javascript – 将输入框转换为combobox以进行jQuery自动完成,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
$(function () { var availableTags = new Array(1000000); var j = 0; for (var i = 1; i < availableTags.length; i++) { availableTags[j++] = i.toString(); } $("#tags").autocomplete({ source: function (req,responseFn) { var re = req.term; var matcher = new RegExp("^" + re,"i"); var a = $.grep(availableTags,function (item) { return matcher.test(item); }); responseFn(a.slice(0,5)); },SELEct: function (event,ui) { if (ui.item && ui.item.value) { var titleinput = ui.item.value; ui.item.value = $.trim(titleinput); alert(ui.item.value); } },change: function (event,ui) { if (!valid) { // remove invalid value,as it didn't match anything $(this).val(""); SELEct.val(""); return false; } } }); });
.custom-comboBox { position: relative; display: inline-block; border-style: solid; border-width: 1px; } .custom-comboBox-toggle { position: absolute; top: 0; bottom: 0; margin-left: -1px; padding: 0; } .custom-comboBox-input { margin: 0; padding: 5px 10px; } /* .custom-comboBox-list-item { color: blue; font-weight: bold; } .custom-comboBox-input,.custom-comboBox-list-item.ui-state-focus { color: black; font-weight: bold; font-style: italic; } */ #tags { width: 40px; }
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.1.min.js"></script> <script type="text/javascript" src="https://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css"> <label for="tags">Tags: </label> <input id="tags" type="text" class="custom-comboBox" value="">
<label for="tags">Tags: </label> <input id="tags" name="tags" type="text" list="options" class="custom-comboBox" value=""> <datalist id="options"> <!-- it puts the options here then the input type text gets them as SELEct options --> </datalist> $(function () { var availableTags = new Array(10); var j = 0; for (var i = 1; i < availableTags.length; i++) { $('#options').append("<option value='" + i + "'>"); } });
以上是大佬教程为你收集整理的javascript – 将输入框转换为combobox以进行jQuery自动完成全部内容,希望文章能够帮你解决javascript – 将输入框转换为combobox以进行jQuery自动完成所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。