JS判断是否开启大小写

JS判断是否开启大小写_第1张图片


<html>
    <head>
        <meta charset="utf-8">
        <title>JS判断是否开启大小写title>
    head>
    <body>
        <input type="text" id="input">
        <h1 style="display:none;">大写已经开启了!h1>
    body>
html>
<script>

    var input = document.querySelector("#input");
    var h1 = document.querySelector("h1");

    function toggle(elem){
        if(elem.style.display == "block"){
            elem.style.display = "none";
        }else{
            elem.style.display = "block";
        }
    }

    input.onkeydown = function(e){
        var e = e || window.event;
        var capsLockKey = e.keyCode ? e.keyCode : e.which;
        if(e.keyCode == 20){
            toggle(h1);
        }else{
            h1.style.display = "none";
        }
    }

script>

你可能感兴趣的:(web前端,javascript)