0

我想在输入文本框中保留一些搜索历史记录,然后我将 autocomplete="on" 属性放在我的输入字段上,但它仅在页面重新加载或刷新时才有效。

这是我在 app.js 中引用的 localStorage 方法,我可以保存输入历史控制台,如 ["123123","123123","abc123","dkiwksiwdADS","33333","555555","QWQWQWQW"] ,但是当我双击文本框(可能是 index.html 中的 div)时,如何放置这些保存的历史记录?

我的代码: app.js:

......                               
        search.getHistory = function() {
                                        console.log($window.localStorage.myObj);
                                        }

        search.runreportsearch = function () {
            var history;
                                        if ($window.localStorage.myObj){
                                            history = JSON.parse($window.localStorage.myObj);
                                            if (angular.isArray(history)){
                                                history.push(search.searchboxinput);
                                            } else {
                                                history = [];
                                                history.push(search.searchboxinput);
                                            }
                                            $window.localStorage.myObj=JSON.stringify(history);
                                            console.log($window.localStorage.myObj);
                                        } else {
                                            history = [];
                                            history.push(search.searchboxinput);
                                            $window.localStorage.myObj=JSON.stringify(history);
                                            console.log($window.localStorage.myObj);

索引.html

        <div class="col-sm-6">
                <h4><input type="text" class="form-control text-center" ng-model="search.searchboxinput" ng-dblclick="search.getHistory()" placeholder="Enter term to search"/></h4>
            </div>
4

0 回答 0