如何检测“搜索”的清除HTML5输入? [英] How do you detect the clearing of a "search" HTML5 input?

查看:96
本文介绍了如何检测“搜索”的清除HTML5输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTML5中,搜索输入类型出现,右侧有一个X,将清除文本框(至少在Chrome中,也许是其他)。有没有办法检测在JavaScript或jQuery中什么时候点击这个X,比如说,检测到什么时候点击该框或进行某种位置点击检测(x位置/ y位置)?

In HTML5, the search input type appears with a little X on the right that will clear the textbox (at least in Chrome, maybe others). Is there a way to detect when this X is clicked in javascript or jQuery other than, say, detecting when the box is clicked at all or doing some sort of location click-detecting (x-position/y-position)?

推荐答案

实际上,当用户搜索时,或者当用户点击x时,有一个搜索事件被触发。这是特别有用的,因为它了解增量属性。

Actually, there is a "search" event that is fired whenever the user searches, or when the user clicks the "x". This is especially useful because it understands the "incremental" attribute.

现在,我已经说过,我不知道你是否可以区分点击x 和搜索,除非你使用onclick黑客。无论哪种方式,希望这有助于。

Now, having said that, I'm not sure if you can tell the difference between clicking the "x" and searching, unless you use an "onclick" hack. Either way, hopefully this helps.


参考文献:

References:

http://help.dottoro.com/ljdvxmhr.php

这篇关于如何检测“搜索”的清除HTML5输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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