📜  按下回车后的 html javascript 调用函数 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:29.443000             🧑  作者: Mango

代码示例1
var yourElement = document.getElementById("yourElement");
yourElement.addEventListener("keydown", function (e) {
    if (e.code === "Enter") {  //checks whether the pressed key is "Enter"
        validate(e);
    }
});

function validate(e) {
    var text = e.target.value;
    //validation of the input...
}