Вы также можете сделать это через плагин selectize.
См. Регистрацию мероприятия в конце.
/**
* Plugin: "dropdown_header" (selectize.js)
* Copyright (c) 2013 Brian Reavis & contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
*/
Selectize.define('dropdown_header', function(options) {
\t var self = this;
\t options = $.extend({
\t \t title : 'Untitled',
\t \t headerClass : 'selectize-dropdown-header',
\t \t titleRowClass : 'selectize-dropdown-header-title',
\t \t labelClass : 'selectize-dropdown-header-label',
\t \t closeClass : 'selectize-dropdown-header-close',
\t \t html: function(data) {
\t \t \t return (
\t \t \t \t '<div class="' + data.headerClass + '">' +
\t \t \t \t \t '<div class="' + data.titleRowClass + '">' +
\t \t \t \t \t \t '<span class="' + data.labelClass + '">' + data.title + '</span>' +
\t \t \t \t \t \t '<a href="javascript:void(0)" class="' + data.closeClass + '">×</a>' +
\t \t \t \t \t '</div>' +
\t \t \t \t '</div>'
\t \t \t);
\t \t }
\t }, options);
\t self.setup = (function() {
\t \t var original = self.setup;
\t \t return function() {
\t \t \t original.apply(self, arguments);
\t \t \t self.$dropdown_header = $(options.html(options));
\t \t \t self.$dropdown.prepend(self.$dropdown_header);
\t \t \t this.$control.on('keydown', function(e) {
\t \t \t \t //alert('A keypess $control!');
\t \t \t });
\t \t \t this.$wrapper.on('keydown', function(e) {
\t \t \t \t //alert('A keypess $wrapper!');
\t \t \t });
\t \t \t this.$input.on('keydown', function(e) {
\t \t \t \t alert('A keypess $input!');
\t \t \t });
\t \t };
\t })();
});