Автозаполнение с гиперссылкой - PullRequest
0 голосов
/ 08 мая 2019

У меня есть код с выпадающим списком автозаполнения, однако я хотел бы, чтобы результаты были URL-ссылками на другие страницы моего сайта.Я знаю, что доступны различные автозаполнения, но этот подходит для нужд моего сайта.

Любая помощь действительно приветствуется

Код предоставлен https://codular.com/demo/jquery-autocomplete-suggestion-dropdown.html

var data = [{
name: "Paul",
description: 'Somebody'
    }, {
name: 'Ben',
description: 'The Other Writer'
    }, {
name: 'Joel',
description: 'The CodeIgniter Writer ' 
            }, { 
    name: 'Mark ', 
    description: 'Made Up Person #1' 
           }]; 
// Suggest section holder var $suggestedHL = $('.suggest-holder'); //
Suggestions UL
var $suggestedUL = $('ul', $suggestedHL); // Suggestions LI var
$suggestedLI = $('li', $suggestedHL); // Selected Items UL var $selectedUL =
$('#selected-suggestions'); // Keyboard Nav Index var index = -1;     // Add a
        suggestion to the selected holder
        function addSuggestion(el) {
            $selectedUL.append($(' < ul > < li > ' + el.find('.suggest - name ').html() + ' < /li> < li style = "list-style: none" > ')); } $('
                        input ', $suggestedHL).on({ keyup:
                        function(e) {
                            var m = false;
                            if (e.which == 38) { // Down arrow - Check that
                                we 've not tried to select before the first item if (--index &lt; 0) { index =
                                0;
                            } // Set a variable to show that we've done some keyboard navigation m =
                            true;
                        } else if (e.which == 40) { // Up arrow - Check that index is not
                            beyond the last item
                            if (++index & gt; $suggestedLI.length - 1) {
                                index = $suggestedLI.length - 1;
                            } // Set a variable to show that we've done some
                            keyboard navigation m = true;
                        } // Check we've done keyboard navigation if
                        (m) { // Remove the active class $('li.active',
                            $suggestedHL).removeClass('active'); $suggestedLI.eq(index).addClass('active');
                    }
                    else if (e.which == 27) {
                        index = -1; // Esc key $suggestedUL.hide(); } else if (e.which == 13) { // Enter
                        key
                        if (index & gt; - 1) {
                            addSuggestion($('li.active', $suggestedHL));
                            index = -1;
                            $('li.active', $suggestedHL).removeClass('active');
                        }
                    } else {
                        index = -1; // Clear the ul $suggestedUL.empty(); // Cache the search term $search =
                        $(this).val(); // Search regular expression $search = new
                        RegExp($search.replace(/[^0-9a-z_]/i), 'i'); // Loop through the array for
                        (var i in data) {
                            if (data[i].name.match($search)) {
                                $suggestedUL.append($(" < /li> < li > < span class = 'suggest-name' > " + data[i].name + " < /span><span class=
                                        'suggest-description' > " + data[i].description + " < /span> < /li> < li style = "list-style: none" > ")); } } // Show the ul $suggestedUL.show(); }
if ($(this).val() == '') {
$suggestedUL.hide();
}
}, keydown: function(e) {
if (e.which == 38 || e.which == 40 || e.which == 13) {
e.preventDefault();
}       
},    focus: function(e) {
                                        if ($(this).val() != '') {
                                            $suggestedUL.show();
                                        }
                                    }

});
$suggestedHL.on('click', 'li', function(e) {
                                addSuggestion($(this));

});
 $('body').on('click', function(e) {
    if (!$(e.target).closest('.suggest-holder
 li, .suggest - holder input ').length) { $suggestedUL.hide(); }; }); < /li>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...