JS開(kāi)發(fā)假百度

效果圖:
image.png
背景圖:
logo.png
CSS代碼:
                html{
            width: 100%;
            height: 100%;
        }
        body {
            margin: 0;
            width: 100%;
            height: 100%;
            position: relative;
        }

        #search-box {
            width: 641px;
            height: 300px;
            position: absolute;
            margin: auto;
            left: 0;
            right: 0;
            top: 0;
            bottom: 200px;
        }

        #search-form {
            font-size: 0px;

        }

        #logo {
            width: 270px;
            height: 129px;
            background-image: url('./logo.png');
            background-size: cover;
            margin: 0 auto;
            margin-bottom: 15px;
        }

        #search-input {
            width: 521px;
            height: 20px;
            line-height: 20px;
            font-size: 16px;
            padding: 9px 7px;
            border: 1px solid #b8b8b8;
        }

        #search-botton {
            width: 104px;
            height: 40px;
            border: 1px solid #38f;
            border-bottom: 1px solid #2e7ae5;
            background-color: #38f;
            color: #fff;
            font-size: 18px;
            position: relative;
            top: 2px;
            cursor: pointer;
        }

        #search-botton:hover {
            background-color: #377ad8;
        }

        #suggestions {
            width: 535px;
            border: 1px solid #d8d8d8;
            position: absolute;
            display: none;
        }

        #suggestions ul {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        #suggestions li {
            font-size: 16px;
            height: 20px;
            line-height: 20px;
            padding: 3px 7px;
            cursor: pointer;
            background-color: #fff;
        }

        #suggestions li:hover {
            background-color: #f8f8f8;
        }
HTML代碼:
      <div id="search-box">
        <div id="logo"></div>
        <div id="search-form">
            <input type="text" id="search-input">
            <button id="search-botton">百度一下</button>
        </div>
        <div id="suggestions">
            <ul id="suggestion-wrap">
            </ul>
        </div>
    </div>
JS代碼,記得引入JQuery:
<script src="./jquery2.1.1.js"></script>
    <script>
        $('#search-input').keydown(function() {
             var text = $(this).val();
             $.ajax({
                url: 'https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=' + text + '&json=1&p=3&sid=20144_1467_19033_20515_18240_17949_20388_20456_18133_17001_15202_11615&req=2&csor=2&pwd=s&cb=jQuery110207612423721154653_1467355506619&_=1467355506623',
                type: 'GET',
                dataType: 'jsonp',
                jsonpCallback: 'jQuery110207612423721154653_1467355506619',
                success:function(data){
                    var data = data.s;
                    var lis = data.reduce(function (result, item) {
                        return result += '<li>' + item + '</li>'
                    }, '')
                    $('#suggestion-wrap').html(lis);
                    $('#suggestions').show().css({
                        top: $('#search-form').offset().top + $('#search-form').height() - 100+'px',
                        left: 0
                    });
                }
             })
        });
        $(document).click(function() {
            $('#suggestions').hide();
        });

        $('#suggestions').on('click', 'li', function() {
            window.location. + $(this).val();
        });

        $('#search-botton').click(function() {
            window.location. + $.trim($('#search-input').val())
        });

        $(document).keypress(function(e) {  
            // 回車鍵事件  
            if(e.which == 13) {  
                window.location. + $.trim($('#search-input').val())
                
            }  
        }); 
    </script>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容