本文介绍了如何将jQuery自动完成附加到输入元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将自动完成功能附加到jquery输入元素.我从此链接在此处输入链接描述下载了jquery小部件v1.12.1(仅自动完成).
I want to attach autocomplete to jquery input element. I downloaded jquery widget v1.12.1 ( only autocomplete) from this link enter link description here.
function maintest () {
let table;
let row1;
let row2;
let cell0;
let cell1;
let header2;
let autocomplete1;
table = $('<table>');
table.attr({"id":"testtable"});
row1 = $('<tr>');
table.append(row1);
header2 = $('<th>').text("Feature/Description");
row1.append(header2);
row2 = $('<tr>');
table.append(row2);
cell1 = $('<td>');
row2.append(cell1);
autocomplete1 = $("<input>").attr({"id" : "selector0"});
/*$("#selector0").autocomplete( "option", "source", [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby" ] );
cell1.append(autocomplete1);*/
$("#mainDiv").append(table);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<body onload="maintest()">
<div id="mainDiv"></div>
</body>
注意:我评论了自动填充功能,因为找不到适合自动填充功能的jQuery小部件的cdn
我的要求是在输入框中添加自动填充
My requirement is to add autocomplete to input box
推荐答案
在调用选项之前,您似乎需要添加自动完成功能.这是CodePen的有效版本: https://codepen.io/edlucas/pen/mdJejqo
It looks like you need to add the autocomplete before you call options on it. Here's a working CodePen version: https://codepen.io/edlucas/pen/mdJejqo
function maintest () {
let table;
let row1;
let row2;
let cell0;
let cell1;
let header2;
let autocomplete1;
table = $('<table>');
table.attr({"id":"testtable"});
row1 = $('<tr>');
table.append(row1);
header2 = $('<th>').text("Feature/Description");
row1.append(header2);
row2 = $('<tr>');
table.append(row2);
cell1 = $('<td>');
row2.append(cell1);
autocomplete1 = $("<input>").attr({"id" : "selector0"});
cell1.append(autocomplete1);
$("#mainDiv").append(table);
$("#selector0").autocomplete();
$("#selector0").autocomplete( "option", "source", [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby" ] );
}
这篇关于如何将jQuery自动完成附加到输入元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!