Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 搜索栏:列表项标记中包含的定位标记不可选择_Javascript_Html_Django_Search - Fatal编程技术网

Javascript 搜索栏:列表项标记中包含的定位标记不可选择

Javascript 搜索栏:列表项标记中包含的定位标记不可选择,javascript,html,django,search,Javascript,Html,Django,Search,我有一个类似谷歌搜索栏的风格的搜索栏,当你在文本框中键入时,它会根据用户输入给出建议。它过滤无序列表中包含的一组项目,并运行下面的myFunction()解析无序列表和显示项目。唯一的问题是,当您单击搜索栏中显示的项目时,链接重定向不起作用,我认为这是因为onmousebutnup事件没有在列表项目上注册(因为当我单击并按住按钮时,如果有意义的话,它会使项目消失)…有什么想法 <input style="border-radius: 7px 0px 0px 7px; border-righ

我有一个类似谷歌搜索栏的风格的搜索栏,当你在文本框中键入时,它会根据用户输入给出建议。它过滤无序列表中包含的一组项目,并运行下面的myFunction()解析无序列表和显示项目。唯一的问题是,当您单击搜索栏中显示的项目时,链接重定向不起作用,我认为这是因为onmousebutnup事件没有在列表项目上注册(因为当我单击并按住按钮时,如果有意义的话,它会使项目消失)…有什么想法

<input style="border-radius: 7px 0px 0px 7px; border-right: 0px; resize: none" id="myInput" onkeyup="myFunction()" name="searchedItem" rows="1" class="form-control" form="searchForm" placeholder="What can we help you find?">
                  <ul id=myUL>
                    <li><a href="http://127.0.0.1:8000/products/{{ obj.productName }}">{{obj.productName}}</a></li>
                  </ul>



<script>
var UL = document.getElementById("myUL");
// hilde the list by default
UL.style.display = "none";

var searchBox = document.getElementById("myInput");

// show the list when the input receive focus
searchBox.addEventListener("focus",  function(){
    // UL.style.display = "block";
});

// hide the list when the input receive focus
searchBox.addEventListener("blur", function(){
    UL.style.display = "none";
});


function myFunction() {
    var input, filter, ul, li, a, i;
    input = document.getElementById("myInput");
    ul = document.getElementById("myUL");
    filter = input.value.toUpperCase();
    // if the input is empty hide the list
    if(filter.trim().length < 1) {
        ul.style.display = "none";
        return false;
    } else {
        ul.style.display = "block";
    }

    li = ul.getElementsByTagName("li");
    for (i = 0; i < li.length; i++) {
        a = li[i].getElementsByTagName("a")[0];

        // This is when you want to find words that contain the search string
     if (a.innerHTML.toUpperCase().indexOf(filter) > -1) {
        li[i].style.display = "";
     } else {
        li[i].style.display = "none";
    }

    <!--// This is when you want to find words that start the search string
    /*if (a.innerHTML.toUpperCase().startsWith(filter)) {
        li[i].style.display = "";
    } else {
        li[i].style.display = "none";
    }*/-->
    }
}
</script>

var UL=document.getElementById(“myUL”); //默认情况下,隐藏列表 UL.style.display=“无”; var searchBox=document.getElementById(“myInput”); //输入接收焦点时显示列表 searchBox.addEventListener(“焦点”,函数(){ //UL.style.display=“块”; }); //当输入接收焦点时隐藏列表 searchBox.addEventListener(“blur”,function()){ UL.style.display=“无”; }); 函数myFunction(){ var输入、滤波器、ul、li、a、i; 输入=document.getElementById(“myInput”); ul=document.getElementById(“myUL”); filter=input.value.toUpperCase(); //如果输入为空,则隐藏列表 如果(过滤器修剪().长度<1){ ul.style.display=“无”; 返回false; }否则{ ul.style.display=“块”; } li=ul.getElementsByTagName(“li”); 对于(i=0;i-1){ 李[i].style.display=“”; }否则{ li[i].style.display=“无”; } } }
有人请帮忙有人请帮忙