js按下回车键调用方法
下面有两种方法,要注意键盘上有两个“Enter”键,方法1对于数字区域的“Enter”键无效。
1、方法一:
// mounted或created中都可
mounted: function () {
// 页面加载自动获取焦点
let inputRoomId = document.getElementById("roomId");
inputRoomId.focus();
var _that=this;
document.onkeydown = function(e) {
if(e.code=='Enter'){
_that.joinMeeting();
}
}
},
2、方法2:
mounted: function () {
// 页面加载自动获取焦点
let inputRoomId = document.getElementById("roomId");
inputRoomId.focus();
var _that=this;
document.onkeydown = function(e) {
if(e.keyCode == 13){
_that.joinMeeting();
}
}
},