zoukankan      html  css  js  c++  java
  • 搜索框内容自动显示

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <title>搜索框输入文字自动提示</title>
        <link rel="stylesheet" href="./asset/bootstrap/dist/css/bootstrap.min.css">
        <style type="text/css">
            .container {
                padding-top: 150px;
            }
            
            .list-group {
                display: none;
            }
        </style>
    </head>
    
    <body>
        <div class="container">
            <div class="form-group">
                <input type="text" class="form-control" placeholder="请输入搜索关键字" id="search">
                <ul class="list-group" id="list-box">
    
                </ul>
            </div>
        </div>
    
        <script src="./js/ajax.js"></script>
        <script src="./js/template-web.js"></script>
        <script type="text/html" id="tpl">
            {{each result }}
            <li class="list-group-item">{{$value}}</li>
            {{/each}}
        </script>
        <script>
            var search = document.querySelector("#search")
            var listBox = document.querySelector('#list-box')
            var timer = null
            search.oninput = function() {
                clearTimeout(timer)
                var key = this.value;
                if (key.trim().length == 0) {
                    listBox.style.display = 'none';
                    return
                }
                timer = setTimeout(function() {
                    ajax({
                        type: 'get',
                        url: 'http://localhost:3001/searchAutoPrompt',
                        data: {
                            key: key
                        },
    
                        success: function(result) {
                            var html = template("tpl", {
                                result: result
                            })
                            listBox.innerHTML = html
                            listBox.style.display = 'block'
                        },
                        error: function() {}
                    })
                }, 800)
    
    
            }
        </script>
    </body>
    
    </html>
    

      

  • 相关阅读:
    Delphi公用函数单元
    Delphi XE5 for Android (十一)
    Delphi XE5 for Android (十)
    Delphi XE5 for Android (九)
    Delphi XE5 for Android (八)
    Delphi XE5 for Android (七)
    Delphi XE5 for Android (五)
    Delphi XE5 for Android (四)
    Delphi XE5 for Android (三)
    Delphi XE5 for Android (二)
  • 原文地址:https://www.cnblogs.com/rainbowupdate/p/13052200.html
Copyright © 2011-2022 走看看