zoukankan      html  css  js  c++  java
  • ajax 模仿百度下拉

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <style>
    #text{
        300px;
        height:30px;
        padding:5px;
        border:1px solid #f90;
        font-size:16px;
        }
    #ul1{
        310px;
        padding:0;
        margin:0;
        border:1px solid #f90;
        display:none;
        }
    li a{
        line-height:30px;
        padding:5px;
        text-decoration:none;
        color:black;
        display:block;
        }
    li a:hover{
        background:#f90;
        color:white;}            
    </style>
    <script>
    function may(data)
    {
        var oul1 = document.getElementById('ul1');
        var html = '';
        
        if(data.s.length)
        {
            oul1.style.display = 'block';
            for(var i = 0; i < data.s.length; i++)
            {
                html += '<li><a target= "_blank" href="http://www.baidu.com/s?wd='+data.s[i]+'">'+data.s[i]+'</a></li>'
            }
            oul1.innerHTML = html;
        }
        else
        {
            oul1.style.display = 'none';
        }
    }
    
    window.onload = function ()
    {
        var otext = document.getElementById('text');
        var oul1 = document.getElementById('ul1');
        
        otext.onkeyup = function ()
        {
            if(this.value != '')
            {
                var oscript = document.createElement('script');
                oscript.src = 'http://suggestion.baidu.com/su?wd='+this.value+'&cb=may';
                document.body.appendChild(oscript);
            }
            else
            {
                oul1.style.display = 'none';
            }
        }
    }
    
    </script>
    </head>
    
    <body>
    <input id="text" type="text">
    
    <ul id="ul1">
        <li><a href="#">1</a></li>
        <li><a href="#">2</a></li>
        <li><a href="#">3</a></li>
    </ul>
    </body>
    </html>
  • 相关阅读:
    redis 持久化
    Linux 配置 FastDFS
    查询相关
    外键查询
    pycharm 使用git
    比较时间
    文件导入import
    切分,字符串转列表
    时间相关
    django 自带序列化组件效果
  • 原文地址:https://www.cnblogs.com/mayufo/p/4299726.html
Copyright © 2011-2022 走看看