JS「entrada」demostración

<!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>demo</title>
    <style>
        input {
            color: #999;
        }
    </style>
</head>
<body>
    <input type="text" value="手机">
    <script>
        // 1.获取元素
        var de = document.querySelector("input");
        // 2.聚焦的操作
        de.onfocus = function(){
            if(de.value==='手机'){
                de.value='';
            }
            de.style.color="#333";
        }
        // 3.失焦的操作
        de.onblur = function(){
            if(de.value===''){
                de.value='手机';
            }
            de.style.color='#999'
        }
    </script>
</body>
</html>

Supongo que te gusta

Origin blog.csdn.net/weixin_60789461/article/details/123610272
Recomendado
Clasificación