Показать сообщение отдельно
  #2 (permalink)  
Старый 25.12.2015, 12:55
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,064

Mister N,
<!doctype html>
<html lang="en">
<head>
   <meta charset="utf-8">
  <title>autocomplete demo</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

</head>

<body>
<label for="autocomplete">Select: </label>
<input id="userSearch">
<script>
function split(val){
  return val.split( /,\s*/ );
}
var data = [{"label":"orange","id":"l_25"},{"label":"apple","id":"l_38"},{"label":"banana","id":"l_44"}];
$( "#userSearch" ).autocomplete({
  source: function( request, response ) {
          response($.map(data, function(item) {
              return {
                label: item.label,
                value: item.id
              }
            }))
      },

  select: function(event, ui){
    var terms = split(this.value);
    terms.pop();
    terms.push(ui.item.value);
    terms.push("");
    this.value = terms.join(", ");
    return false;
  },
      minLength: 0,
      cache: false
});
</script>
</body>
</html>
Ответить с цитированием