HLJ 发布于
2023-06-17 09:53:41
31阅读

JavaScript onbeforeinput事件禁止输入数字

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <textarea></textarea>
</body>

</html>
<script>
    let textarea = document.querySelector('textarea')

    textarea.onbeforeinput = function (e) {
        let RegEx = /[0-9]/
        if (RegEx.test(e.data)) {
            e.returnValue = false
        }
    }
</script>
当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2023-06-17/629.html
最后生成于 2024-06-22 12:07:39
此内容有帮助 ?
0