Vue implements input to store up to 10 input values

clipboard.png
is similar to the input box effect of Si No. I"ve tried that the native autocomplete property doesn"t work. -sharp-sharp-sharp problem description

Apr.01,2022

check whether input adds name


clipboard.png


you might as well write one yourself, save it locally every time you search, and be compatible with major browsers


.

to achieve the function, only click on the search conditions to save, only show 10 items;


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>localStorege</title>
</head>
<body>
    <input id="box-input" type="text" />
    <button id="btn">search</button>
    <div id="search-list"></div>
</body>
<script type="text/javascript">
    window.onload = function(){
        localStorage.clear();
        var vla = document.getElementById("box-input"),
            btn = document.getElementById("btn"),
            searchList = document.getElementById("search-list");
        btn.onclick = function(){
            var result = [];
            var isResult = JSON.parse(localStorage.getItem("resultArr"));
            if(!!isResult){
                result = result.concat(isResult)
            };
            if(!!vla.value){
                result.unshift(vla.value);
            };
            localStorage.setItem("resultArr", JSON.stringify(result))
        };
        vla.onfocus = function(){
            var isResult = JSON.parse(localStorage.getItem("resultArr"));
            if(!!isResult){
                var max = "";
                if(isResult.length>9){
                    max = 10
                }else{
                    max = isResult.length
                };
                for (var i=0; i<max; iPP){
                    var p = document.createElement("p");
                    p.innerHTML = isResult[i]
                    searchList.appendChild(p)
                }
            }
        };
        vla.onblur = function(){
            var childs = searchList.childNodes;
            for(var i = childs .length - 1; i >= 0; i--) {
                searchList.removeChild(childs[i]);
            }
        }
    }
</script>
</html>
Menu