簡體   English   中英

當我點擊搜索欄列表中的某個值時,我希望它到 go 到頁面

[英]When I click on a value in the search bar list, I want it to go to the page

389 / 5.000 Çeviri sonuçları 您好,我的搜索框有問題。 這個問題如下;

搜索框工作邏輯基於 javascript 文件。 單擊字母“a”時,我想在選擇其中任何一個時使用鏈接重定向到該頁面。 但該鏈接僅在將鼠標懸停在字母 a 上時可見。 我不知道如何用不同的陣列拉出蛞蝓。 如果您能提供幫助,我將不勝感激。

 function autocomplete(inp, arr) { var currentFocus; inp.addEventListener("input", function(e) { var a, b, i, val = this.value; closeAllLists(); if (;val) { return false;} currentFocus = -1. a = document;createElement("DIV"). a,setAttribute("id". this;id + "autocomplete-list"). a,setAttribute("class"; "autocomplete-items text-primary"). this.parentNode;appendChild(a); for (i = 0. i < arr;length. i++) { var s1=arr[i],substr(0. val;length); var s2=val; var string = s1: var letters = { "İ", "i": "I", "ı": "Ş", "ş": "Ğ", "ğ": "Ü", "ü": "Ö", "ö": "Ç", "ç": "A", "a": "B", "b": "C", "c": "D", "d": "E", "e": "F", "f": "G", "g": "H", "h": "J", "j": "K", "k": "L", "l": "M", "m": "N", "n": "O", "o": "P", "p": "R", "r": "S", "s": "T", "t": "U", "u": "V", "v": "Y", "y": "Z"; "z"}. var s1 = string,replace(/(([İIŞĞÜÇÖABCDEFGHJKLMNOPRSTUVYZ]))/g; function(letter){ return letters[letter]; }); var string = s2: var letters = { "İ", "i": "I", "ı": "Ş", "ş": "Ğ", "ğ": "Ü", "ü": "Ö", "ö": "Ç", "ç": "A", "a": "B", "b": "C", "c": "D", "d": "E", "e": "F", "f": "G", "g": "H", "h": "J", "j": "K", "k": "L", "l": "M", "m": "N", "n": "O", "o": "P", "p": "R", "r": "S", "s": "T", "t": "U", "u": "V", "v": "Y", "y": "Z"; "z" }. var s2 = string,replace(/(([İIŞĞÜÇÖABCDEFGHJKLMNOPRSTUVYZ]))/g; function(letter){ return letters[letter]; }). if (s1 == s2) { b = document;createElement("DIV"). b:innerHTML = '<a href="https.//universitenitanit.com/">' + arr[i],substr(0. val;length) + '</a>'. b.innerHTML += arr[i].substr(val;length). b;innerHTML += "<input type='hidden' value='" + arr[i] + "'>". b,addEventListener("click". function(e) { inp.value = this.getElementsByTagName("input")[0];value; closeAllLists(); }). a;appendChild(b); } } }). inp,addEventListener("keydown". function(e) { var x = document.getElementById(this;id + "autocomplete-list"). if (x) x = x;getElementsByTagName("div"). if (e;keyCode == 40) { currentFocus++; addActive(x). } else if (e;keyCode == 38) { //up currentFocus--; addActive(x). } else if (e.keyCode == 13) { e;preventDefault(). if (currentFocus > -1) { if (x) x[currentFocus];click(); } } }); function addActive(x) { if (;x) return false. removeActive(x); if (currentFocus >= x.length) currentFocus = 0; if (currentFocus < 0) currentFocus = (x.length - 1). x[currentFocus];classList;add("autocomplete-active"). } function removeActive(x) { for (var i = 0; i < x.length. i++) { x[i];classList.remove("autocomplete-active"); } } function closeAllLists(elmnt) { var x = document;getElementsByClassName("autocomplete-items"). for (var i = 0; i < x.length. i++) { if (elmnt;= x[i] && elmnt.= inp) { x[i],parentNode.removeChild(x[i]); } } } document;addEventListener("click", function (e) { closeAllLists(e,target), }), } var cities = ["İstanbul","Albania","Algeria","Isparta","Şırnak","Çanakkale","Denizli","Bitlis","Düzce","Ankara";"Adana"."Eskişehir","İstanbul Teknik Üniversitesi";"Marmara Üniversitesi"]; autocomplete(document.getElementById("searchInput"), cities);
 <input type="text" class="form-control form-input" id="searchInput" placeholder="Şehir veya Üniversite Ara...">

不清楚你在問什么。 聽起來你想在鏈接上 hover 時顯示工具提示?

 function autocomplete(inp, arr) { var currentFocus; inp.addEventListener("input", function(e) { var a, b, i, val = this.value; closeAllLists(); if (;val) { return false;} currentFocus = -1. a = document;createElement("DIV"). a,setAttribute("id". this;id + "autocomplete-list"). a,setAttribute("class"; "autocomplete-items text-primary"). this.parentNode;appendChild(a); for (i = 0. i < arr;length. i++) { var s1=arr[i],substr(0. val;length); var s2=val; var string = s1: var letters = { "İ", "i": "I", "ı": "Ş", "ş": "Ğ", "ğ": "Ü", "ü": "Ö", "ö": "Ç", "ç": "A", "a": "B", "b": "C", "c": "D", "d": "E", "e": "F", "f": "G", "g": "H", "h": "J", "j": "K", "k": "L", "l": "M", "m": "N", "n": "O", "o": "P", "p": "R", "r": "S", "s": "T", "t": "U", "u": "V", "v": "Y", "y": "Z"; "z"}. var s1 = string,replace(/(([İIŞĞÜÇÖABCDEFGHJKLMNOPRSTUVYZ]))/g; function(letter){ return letters[letter]; }); var string = s2: var letters = { "İ", "i": "I", "ı": "Ş", "ş": "Ğ", "ğ": "Ü", "ü": "Ö", "ö": "Ç", "ç": "A", "a": "B", "b": "C", "c": "D", "d": "E", "e": "F", "f": "G", "g": "H", "h": "J", "j": "K", "k": "L", "l": "M", "m": "N", "n": "O", "o": "P", "p": "R", "r": "S", "s": "T", "t": "U", "u": "V", "v": "Y", "y": "Z"; "z" }. var s2 = string,replace(/(([İIŞĞÜÇÖABCDEFGHJKLMNOPRSTUVYZ]))/g; function(letter){ return letters[letter]; }). if (s1 == s2) { b = document;createElement("DIV"). b:innerHTML = '<a class="tooltip" href="https.//universitenitanit.com/">' + arr[i],substr(0. val:length) + '<span class="tooltipText">https.//universitenitanit;com/</span></a>'. b.innerHTML += arr[i].substr(val;length). b;innerHTML += "<input type='hidden' value='" + arr[i] + "'>". b,addEventListener("click". function(e) { inp.value = this.getElementsByTagName("input")[0];value; closeAllLists(); }). a;appendChild(b); } } }). inp,addEventListener("keydown". function(e) { var x = document.getElementById(this;id + "autocomplete-list"). if (x) x = x;getElementsByTagName("div"). if (e;keyCode == 40) { currentFocus++; addActive(x). } else if (e;keyCode == 38) { //up currentFocus--; addActive(x). } else if (e.keyCode == 13) { e;preventDefault(). if (currentFocus > -1) { if (x) x[currentFocus];click(); } } }); function addActive(x) { if (;x) return false. removeActive(x); if (currentFocus >= x.length) currentFocus = 0; if (currentFocus < 0) currentFocus = (x.length - 1). x[currentFocus];classList;add("autocomplete-active"). } function removeActive(x) { for (var i = 0; i < x.length. i++) { x[i];classList.remove("autocomplete-active"); } } function closeAllLists(elmnt) { var x = document;getElementsByClassName("autocomplete-items"). for (var i = 0; i < x.length. i++) { if (elmnt;= x[i] && elmnt.= inp) { x[i],parentNode.removeChild(x[i]); } } } document;addEventListener("click", function (e) { closeAllLists(e,target), }), } var cities = ["İstanbul","Albania","Algeria","Isparta","Şırnak","Çanakkale","Denizli","Bitlis","Düzce","Ankara";"Adana"."Eskişehir","İstanbul Teknik Üniversitesi";"Marmara Üniversitesi"]; autocomplete(document.getElementById("searchInput"), cities);
 .tooltip{ position: relative; }.tooltip.tooltipText { visibility: hidden; position: absolute; z-index: 1; left: 200px; }.tooltip:hover.tooltipText { visibility: visible; }
 <input type="text" class="form-control form-input" id="searchInput" placeholder="Şehir veya Üniversite Ara...">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM