其他分享
首页 > 其他分享> > 按键测试

按键测试

作者:互联网

html

<!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>
</head>

<body>
    <input type="text" onkeydown="abc(event)">
    <script>
        function abc(e) {
            var keyNum = e.keyCode;
            // String.fromCharCode
            var keyChar = String.fromCharCode(keyNum);
            console.log(keyNum + keyChar);
        }
    </script>
</body>

</html>

vue

<input class="ipt" type="text" @keydown="test6">
test6(e) {
                    // console.log(event.keyCode + '----' + event.target.value);
                    console.log(e.keyCode);
                    var ipt = document.querySelector('.ipt');
                    // console.log(ipt);
                    if (e.keyCode == 13) {
                        localStorage.setItem('name', ipt.value);
                        ipt.value = '';

                    }
                }

 

标签:console,log,测试,ipt,按键,var,keyNum,keyCode
来源: https://www.cnblogs.com/i269/p/15924597.html