使用 Javascript 在 iphone 的虚拟键盘中捕获“完成”按钮点击
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4971061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Capture "done" button click in iphone's virtual keyboard with Javascript
提问by Dan
I'm wondering if there's a way to capture the iPhone's virtual keyboard's done button event, using JavaScript?
我想知道是否有办法使用 JavaScript 捕获 iPhone 的虚拟键盘的完成按钮事件?
Basically, I just want to be able to call a JS function when the user clicks done.
基本上,我只是希望能够在用户单击完成时调用 JS 函数。
采纳答案by Alex Reynolds
The done key is the same as the enter key. So you can listen to a keypress event. I'm writing this using jQuery and i use it in coffee script so I'm trying to convert it back to js in my head. Sorry if there is an error.
完成键与回车键相同。因此,您可以收听按键事件。我正在使用 jQuery 编写此代码,并在咖啡脚本中使用它,因此我正在尝试将其转换回 js。如有错误,请见谅。
$('someElem').bind("keypress", function(e){
// enter key code is 13
if(e.which === 13){
console.log("user pressed done");
}
})
回答by Jason Lydon
I was unable to track the 'done' button being clicked. It didn't register any click
s or keypress
es. I had to addEventListener
s for change
, focusout
and blur
using jquery
(because the project already was using jquery
).
我无法跟踪被点击的“完成”按钮。它没有注册任何click
s 或keypress
es。我不得不addEventListener
s for change
,focusout
并blur
使用jquery
(因为项目已经在使用jquery
)。
回答by Krunal
You need to do some kind of this:
你需要做一些这样的事情:
$('someElem').focusout(function(e) {
alert("Done key Pressed!!!!")
});
It worked for me, hope it will help you as well.
它对我有用,希望它也能帮助你。
回答by oron tech
After searching and trying this solutionbasically is say:
在搜索并尝试此解决方案后,基本上是说:
document.addEventListener('focusout', e => {});
tested on IPhone 6s
在 iPhone 6s 上测试
回答by Kelvin Aitken
The answer by oron tech using an event listener is the only one that works cross platform.
oron tech 使用事件侦听器的答案是唯一可以跨平台工作的方法。
document.getElementById("myID").addEventListener("focusout", blurFunction);
function blurFunction() { // Do whatever you want, such as run another function
const myValue = document.getElementById("myID").value;
myOtherfunction(myValue);
}
回答by Dan
attach a blur event to the text box in question. The done fire will fire this event.
将模糊事件附加到相关文本框。done fire 会触发这个事件。