我正在寻找一种方法,只要用户在特定网页上,只要用户开始输入任何内容,它就会自动将击键捕获到弹出的输入框中。它类似于台式机软件中显示的图像,在该软件中,用户开始输入,并将其捕获到输入框中供用户开始搜索。
[check out,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");
});