亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

JavaScript實(shí)現(xiàn)顏色查看器

 更新時(shí)間:2021年04月13日 08:34:00   作者:火星飛鳥  
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)顏色查看器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了JavaScript實(shí)現(xiàn)顏色查看器的具體代碼,供大家參考,具體內(nèi)容如下

實(shí)現(xiàn)效果

  • 方框中初始為白色
  • 輸入框中輸入顏色代碼,點(diǎn)擊查看顏色,在上方即可出現(xiàn)對(duì)應(yīng)顏色
  • 點(diǎn)擊復(fù)原,復(fù)原到初始的白色,同時(shí)清空輸入框的內(nèi)容

實(shí)現(xiàn)代碼

<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8" />
        <title>顏色查看器</title>
        <style>
            #color {
                width: 150px;
                height: 150px;
                background-color: #fff;
                border: 1px solid #000;
            }
        </style>
    </head>
    <body>
        <div id="color"></div>
        <input id="inp" type="text" placeholder="請(qǐng)輸入顏色代碼..." />
        <button id="trans">查看顏色</button>
        <button id="rst">復(fù)原</button>
    </body>
    <script>
        let trans = document.getElementById('trans');
        let color = document.getElementById('color');
        let inp = document.getElementById('inp');
        let rst = document.getElementById('rst');
        trans.addEventListener('click', () => {
            color.style.backgroundColor = inp.value;
        });
        rst.addEventListener('click', () => {
            color.style.backgroundColor = '#fff';
            inp.value = '';
        });
    </script>
</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論