[英]How to automatically open a popup input box when user starts typing
看看这个, https://jsfiddle.net/v1b3m/wmufgy1o/4/ ,我用过jquery,但你也可以用基本的js来做,你可以很容易地在弹出窗口中添加一个按钮,按下时会发送数据到您的数据库。
let word = "";
$(document).keyup(event => {
// find which key has been pressed from the event object
const key = event.originalEvent.key;
// make the hidden modal visible
$("#myModal").css("display", "block");
const ignoreKeys = [
"CapsLock",
"Shift",
"Tab",
"Alt",
"Control",
"PageUp",
"PageDown",
"ArrowUp",
"ArrowDown",
"ArrowRight",
"ArrowLeft",
"Escape",
"Home",
"Insert"
];
if (ignoreKeys.indexOf(key) > -1) {
} else if (key == "Backspace" || key == "Delete") {
word = word.substring(0, word.length - 1);
} else {
word += key;
}
// Update the text content of the modal
$("#my-text").text(word);
});
$(".close").click(() => {
$("#myModal").css("display", "none");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.