custom autocomplete #2

catch me if u can!·2021년 2월 9일
0

목차

참조

https://jquery.com/
https://jqueryui.com/

코드

<head>
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css">
    <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
    <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js" integrity="sha256-eGE6blurk5sHj+rmkfsGYeKyZx3M4bG+ZlFyA7Kns7E=" crossorigin="anonymous"></script>
</head>
<body>
  <input type="text" id="user-email">
</body>
<script>
$("#user-email").keyup(function(){
    var email = this.value;        
    if(email.indexOf("@") == -1) {
        autocomplete_text = [];
        autocomplete_text.push(email+"@gmail.com");
        autocomplete_text.push(email+"@naver.com");
    }
});    
$("#user-email").autocomplete({
    //Minimum input length for automatic completion to be displayed
    minLength:2,        
    source: function(request, response) {
        response(autocomplete_text, function(e, ui) {});
    },
    select: function(e, ui) {
        console.log(ui.item.value);
    },
    focus: function(event, ui) {
        return false;
    }
});
</script>
profile
마쿠투소케 난쿠로나이사

0개의 댓글