欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

smart search front sample

程序员文章站 2022-07-07 15:37:16
...
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8"/>
<body>
    <div style="margin-top: 300px;margin-left: 520px;">
        <form action="{{url_for('api.Ajax_ajax_load_course')}}" method="get" style="margin: auto 0;">
            请输入单词或课程名称:<br/>
            <input type="text" id="search-text" name="q"><button type="button" id='search-button'>搜索</button>
            <p><span id='search-result'></span></p>
        </form>
    </div>
<script src="{{url_for('static',filename='js/jquery.min.js')}}"></script>
<script>
    $(document).ready(function(){
        $("#search-text").keyup(function(){
            var q = $("#search-text").val();
            $.get("{{url_for('api.Ajax_ajax_load_course')}}",{'q':q}, function(data){
                for (var i = data.length - 1; i >= 0; i--) {
                    $('#search-result').append(data[i]+'<br/>')
                };
            })
        });
        $('#search-text').keydown(function(){
            $('#search-result').empty();
        })
        $('#search-text').blur(function(){
            $('#search-result').empty();
        })
    });
</script>
</body>
</html>
相关标签: ajax html