用户开始输入时如何自动打开弹出式输入框

问题描述 投票:-1回答:1

我正在寻找一种方法,只要用户在特定网页上,只要用户开始输入任何内容,它就会自动将击键捕获到弹出的输入框中。它类似于台式机软件中显示的图像,在该软件中,用户开始输入,并将其捕获到输入框中供用户开始搜索。Trade Station Software

javascript
1个回答
0
投票

[check out,https://jsfiddle.net/v1b3m/wmufgy1o/4/,我使用过jquery,但是您也可以使用基本js,您可以轻松地在弹出窗口中添加一个按钮,按下该按钮会将数据发送到数据库。

Sample pop up with text

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");
});
© www.soinside.com 2019 - 2024. All rights reserved.