2021-12-13 15:49:59
通过 js
原生事件的 keyCode
值来判断禁用enter事件实例
<!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>
<textarea rows="6"></textarea>
</body>
<script>
let dom = document.querySelector('textarea')
dom.onkeydown = function(e){
console.log(e.key)
console.log(e.code)
console.log(e.keyCode)
if(e.keyCode == 13){
e.returnValue = false
console.log('禁用enter事件')
}
}
</script>
</html>
最后生成于 2023-06-27 21:38:04
热门推荐: