-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto-complete.js
43 lines (38 loc) · 903 Bytes
/
auto-complete.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var countries = ['United States', 'Canada', 'Argentina', 'Armenia'];
var userInput = "";
var selectedCountries = [];
var list = $('ul');
$('input').on('keyup change', function (e) {
userInput = $(this).val();
list.empty();
selectedCountries = [];
countries.forEach(function (country) {
if (_.includes(country, userInput)) {
selectedCountries.push(country);
}
});
var str = "";
selectedCountries.forEach(function (c) {
str += "<li>" + c + "<\li>";
});
list.html(str);
});
////////////////////HTML//////////////////////////////
// <input placeholder="please enter..."/>
// <ul class="mylist">
// </ul>
/////////////////CSS///////////////////////
// li {
// list-style: none;
// }
//
// ul {
// padding: 0;
// background-color: #eee;
// width: 105px;
// margin: 0;
// }
//
// input {
// width: 100px;
// }