javascript 如何在 iPhone 浏览器上捕获键盘“返回”事件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5932317/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 18:50:20  来源:igfitidea点击:

How to capture the keyboard "Return" event on iPhone browser?

javascriptjqueryiphonekeyboard

提问by locoboy

Is there a way to capture the event in jquery/javascript when a user hits the "Return" key in the iphone browser keyboard? I'm trying to either hide the keyboard on the press or activate some function.

当用户点击 iPhone 浏览器键盘中的“返回”键时,有没有办法在 jquery/javascript 中捕获事件?我试图隐藏按键上的键盘或激活某些功能。

回答by Josiah

You could try this:

你可以试试这个:

<script type="text/javascript">
document.onkeyup=function(e) {
    if(e.which == 13){
        $('inputID').blur();
        //rest of function

        return false;
    }
}
</script>

Are you using a library?

你在使用图书馆吗?

Update
Depending on the application, an input submit would hide the keyboard and trigger a function:

更新
根据应用程序,输入提交将隐藏键盘并触发一个功能:

<form id="searchForm" OnSubmit="doSearch(this.searchTerm.value); return false;">  
  <input type="search" name="searchTerm" autocorrect = "off" />
  <input type="submit" value="Search" class="hidden" />
</form>

You could even hide the input button with CSS: .hidden {display: none;}

你甚至可以用 CSS 隐藏输入按钮: .hidden {display: none;}

回答by locoboy

This is what hides the keyboard:

这是隐藏键盘的原因:

$('#inputID').blur();