Скрипт autocomplete
Пробую сделать refresh страницы c выбранной поисковой подсказкой.
Добавил только эти строки в данный скрипт: var singleText = selected[0]; window.location.href = window.location.href+ "&title="+singleText; В итоге страница обновляется, но в переменную title пишется [object%20HTMLLIElement] а не выбранная подсказка. http://localhost/index.php?id=1&title=[object%20HTMLLIElement] А если так: var singleText = term; то всё бы хорошо, но в переменную вписывается столько символов подсказки сколько было набрано при поиске - набрали ябл высветилось яблоко, нажали на яблоко, в title пишется ябл а не яблоко. Вобщем где найти переменную с выбранной подсказкой? Привожу только функции из js так как всё не поместилось function request(term, success, failure) { if (!options.matchCase) term = term.toLowerCase(); var data = cache.load(term); // recieve the cached data if (data && data.length) { success(term, data); // if an AJAX url has been supplied, try loading the data now } else if( (typeof options.url == "string") && (options.url.length > 0) ){ var extraParams = { timestamp: +new Date() }; $.each(options.extraParams, function(key, param) { extraParams[key] = typeof param == "function" ? param() : param; }); $.ajax({ // try to leverage ajaxQueue plugin to abort previous requests mode: "abort", // limit abortion to this input port: "autocomplete" + input.name, dataType: options.dataType, url: options.url, data: $.extend({ q: encodeURIComponent(lastWord(term)), limit: options.max }, extraParams), success: function(data) { var parsed = options.parse && options.parse(data) || parse(data); cache.add(term, parsed); success(term, parsed); } }); } else { // if we have a failure, we need to empty the list -- this prevents the the [TAB] key from selecting the last successful match select.emptyList(); failure(term); } }; function selectCurrent() { var selected = select.selected(); if( !selected ) return false; var v = selected.result; previousValue = v; if ( options.multiple ) { var words = trimWords($input.val()); if ( words.length > 1 ) { var seperator = options.multipleSeparator.length; var cursorAt = $(input).selection().start; var wordAt, progress = 0; $.each(words, function(i, word) { progress += word.length; if (cursorAt <= progress) { wordAt = i; return false; } progress += seperator; }); words[wordAt] = v; // TODO this should set the cursor to the right position, but it gets overriden somewhere //$.Autocompleter.Selection(input, progress + seperator, progress + seperator); v = words.join( options.multipleSeparator ); } v += options.multipleSeparator; } $input.val(v); hideResultsNow(); $input.trigger("result", [selected.data, selected.value]); return true; } selected: function() { var selected = listItems && listItems.filter("." + CLASSES.ACTIVE).removeClass(CLASSES.ACTIVE); //return selected && selected.length && $.data(selected[0], "ac_data"); var TitleText = selected[0]; window.location.href = window.location.href+ "&title="+TitleText; }, |
rs_ssh,
var singleText = selected[0]; если это элемент то попробуйте взять selected[0].value() или selected.val() |
Цитата:
|
rs_ssh,
увы ваш код неосилил. |
Ok
|
Часовой пояс GMT +3, время: 01:41. |