推荐一个VScode插件,非常nice

JS-CSS-HTML Formatter
保存的文件的时候,自动格式化代码

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>输入框</title>
    <style>
        input {
            color: #999;
        }
    </style>
</head>

<body>
    <input type="text" value="手机">
</body>
<script>
    // onfocus  获取焦点事件
    var text = document.querySelector("input");
    text.onfocus = function() {
        if (this.value === '手机') {
            this.value = '';
        }
        this.style.color = 'black';
    }

    // onblur  失去焦点事件
    text.onblur = function() {
        if (this.value === '') {
            this.value = '手机';
            this.style.color = '#999';
        }

    }
</script>

</html>

你可能感兴趣的:(JavaScript)