最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

利用JavaScript模擬京東快遞單號查詢效果

 更新時間:2022年03月09日 10:58:00   作者:一夕ξ  
這篇文章主要為大家介紹了如何通過JavaScript模擬實現(xiàn)京東的快遞單號查詢效果,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以動手試一試

1、上面放大框開始是隱藏的,當(dāng)輸入單號后,就顯示,并且里面的內(nèi)容是輸入框的內(nèi)容的字體的放大

<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table {
            margin: 20px;
            border: none
        }
        
        p {
            font-size: 15px;
        }
        
        input {
            height: 15px
        }
        
        button {
            background-color: rgb(77, 132, 233);
            border: none;
        }
        
        a {
            text-decoration: none;
            color: white;
            font-size: 15px;
        }
        
        div {
            font-size: 25px;
            width: 100px;
            height: auto;
            border: 1px solid black;
            display: none;
            position: absolute;
            top: 0px
        }
    </style>
</head>
 
<body>
 
    <table>
        <tr>
            <td>
                <p>快遞單號</p>
            </td>
            <td> <input type="text" placeholder="請輸入您的快遞單號"></td>
            <td> <button><a href="">查詢</a></button></td>
        </tr>
    </table>
    <div></div>
 
    <script>
        //當(dāng)開始在輸入框中鍵入內(nèi)容的時候,div模塊就開始顯示,里面的內(nèi)容是input里面的內(nèi)容,但字體變大
        var input = document.querySelector('input')
        var div = document.querySelector('div')
        input.addEventListener('keyup', function() {
            if (input.value != '') {
                div.style.display = 'block'
                div.innerHTML = input.value
            } else {
                div.style.display = 'none'
                div.innerHTML = ''
            }
        })
    </script>
</body>
 
</html>

問題:

1、上面放大框的效果怎么做,倒三角雖然可以使用border來完成,但是效果會有顏色的填充

2、當(dāng)輸入框輸入的文字較多的時候,怎么自動的改變上面放大框的高度和寬度

        .con::before {
            content: '';
            height: 0;
            height: 0;
            position: absolute;
            top: 28px;
            left: 18px;
            border: 8px solid #000;
            border-style: solid dashed dashed;
            border-color: #fff transparent transparent
        }
<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .search {
            position: relative;
            width: 178px;
            margin: 100px
        }
        
        .con {
            position: absolute;
            top: -40px;
            width: 171px;
            border: 1px solid rgba(0, 0, 0, .2);
            box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
            padding: 5px 0;
            font-size: 18px;
            line-height: 20px;
            color: #333;
            display: none;
        }
        
        .con::before {
            content: '';
            height: 0;
            height: 0;
            position: absolute;
            top: 28px;
            left: 18px;
            border: 8px solid #000;
            border-style: solid dashed dashed;
            border-color: #fff transparent transparent
        }
    </style>
</head>
 
<body>
 
    <div class="search">
        <div class="con"></div>
        <input type="text" placeholder="請輸入您的快遞單號" class="jd">
    </div>
 
    <script>
        //當(dāng)開始在輸入框中鍵入內(nèi)容的時候,div模塊就開始顯示,里面的內(nèi)容是input里面的內(nèi)容,但字體變大
        var jd = document.querySelector('.jd')
        var con = document.querySelector('.con')
        jd.addEventListener('keyup', function() { //要區(qū)分keyup、keydown、keypress之間的區(qū)別
            if (jd.value != '') {
                con.style.display = 'block'
                con.innerHTML = jd.value
            } else {
                con.style.display = 'none'
                con.innerHTML = ''
            }
        })
    </script>
</body>
 
</html>

如果換成keydown或者keypress來注冊事件的話,會少一個字,這是因為文字還沒有落入文本框的時候,就以及觸發(fā)了事件,但此時里面的內(nèi)容還是空的,因此上面的文本框是不顯示的。第二次按下的時候,立刻觸發(fā)事件,此時字并沒有進(jìn)入盒子,盒子里面留下的只有前一個字。

注意區(qū)別

keypress更加不行,因為對于功能鍵是沒有效果的。

4、當(dāng)失去焦點的時候,就隱藏con。得到焦點就顯示(onfocus、onblur)

    <script>
        //當(dāng)開始在輸入框中鍵入內(nèi)容的時候,div模塊就開始顯示,里面的內(nèi)容是input里面的內(nèi)容,但字體變大
        var jd = document.querySelector('.jd')
        var con = document.querySelector('.con')
        jd.addEventListener('keyup', function() { //要區(qū)分keyup、keydown、keypress之間的區(qū)別
            if (jd.value != '') {
                con.style.display = 'block'
                con.innerHTML = jd.value
            } else {
                con.style.display = 'none'
                con.innerHTML = ''
            }
        })
        jd.addEventListener('focus', function() {
            if (jd.value != '') {
                con.style.display = 'block'
            }
        })
        jd.addEventListener('blur', function() {
            con.style.display = ''
        })
    </script>

以上就是利用JavaScript模擬京東快遞單號查詢效果的詳細(xì)內(nèi)容,更多關(guān)于JavaScript快遞單號查詢的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論

惠安县| 尖扎县| 广安市| 米泉市| 乌兰察布市| 光山县| 青铜峡市| 股票| 龙胜| 江津市| 泰安市| 泰安市| 奈曼旗| 昂仁县| 济宁市| 广饶县| 无为县| 岫岩| 莒南县| 剑川县| 益阳市| 抚顺县| 鲁山县| 阿勒泰市| 宁乡县| 保山市| 长宁区| 德州市| 盐源县| 泗洪县| 修水县| 巨野县| 得荣县| 社旗县| 柘城县| 锦屏县| 乐至县| 错那县| 枣阳市| 平湖市| 吉安县|