输入/ I标记应该以&LT使用哪一种“事件”;在iOS / Android的元素? [英] Which 'event' should I use with an <input/> element on an iOS/Android?

查看:156
本文介绍了输入/ I标记应该以&LT使用哪一种“事件”;在iOS / Android的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示/隐藏结果时,用户开始在输入元素的搜索栏中键入。

我可以用一些有趣的事件是


  • 鼠标按下/鼠标松开

  • touchstart / touchend

  • 焦点

或者完全忽略click事件,只是使用的变事件1.检测是否文本在搜索框中present,2响应相应。

由于有许多潜在的细微差别专对面,我没有自己的并不能测试,我希望我应该使用来处理这种情况的事件有人能告诉我的设备。

* - 注 - 演示需要以下的手动编辑,直到配置了相应的事件

  $(#本地过滤-列表视图),隐藏();
 $(#defaultHomeContent),隐藏()。


解决方案

现在看来似乎真的取决于你想要的确切行为是什么。如果您希望当用户第一次与外地从事触发动作,那么你要触发基于:

  touchstart
鼠标按下
焦点

如果你想只有当内容在现场更改为触发,你可以回答:

 输入

如果你也想IE9之前,支持IE(不支持输入事件,那么你可能还想要触发基于:

  KEYUP
下降

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
  • 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.

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:

keyup
drop

这篇关于输入/ I标记应该以&LT使用哪一种“事件”;在iOS / Android的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆