简体   繁体   English

我应该将哪个“事件”与 <input/> iOS / Android上的元素?

[英]Which 'event' should I use with an <input/> element on an iOS/Android?

I need to show/hide results when a user starts to type in the search field of an input element. 当用户开始在输入元素的搜索字段中键入内容时,我需要显示/隐藏结果。

Some interesting events I can use would be 我可以使用一些有趣的事件

  • mousedown / mouseup mousedown / mouseup
  • touchstart / touchend 触摸开始/触摸结束
  • focus 焦点

or perhaps ignore the "click" event altogether and just use the "change" event to 1. detect if text is present in the search box, 2. respond accordingly. 或者完全忽略“单击”事件,而只是将“更改”事件使用为1.检测搜索框中是否存在文本,2.相应地进行响应。

Since there are potentially many nuances specifically across devices which I don't own and can't test, I'm hoping someone can tell me which event I should be using to handle this scenario. 由于在我不拥有且无法测试的设备之间可能存在许多细微差别,因此我希望有人可以告诉我应该使用哪个事件来处理这种情况。

*- Note - the demo requires manual editing of the following until the proper event is configured *-注意-该演示需要手动编辑以下内容,直到配置了正确的事件为止

 $("#local-filterable-listview").hide();
 $("#defaultHomeContent").hide();

It seems like it really depends on what you want the exact behavior to be. 看来这确实取决于您想要的确切行为。 If you want to trigger an action when the user first engages with the field, then you'd want to trigger based on: 如果您想在用户首次与该字段互动时触发操作,那么您将基于以下条件触发:

touchstart
mousedown
focus

If you want to trigger only when content is changed in the field, you can respond to: 如果只想在字段中的内容更改时触发,则可以响应:

input

If you also want to support IE before IE9 (which doesn't support the input event, then you may also want to trigger based on: 如果您还想在IE9之前支持IE(不支持input事件),则可能还需要基于以下条件触发:

keyup
drop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM