1
我正在使用jQuery Mobile的phoneGap在Android中创建应用程序。Jquery Mobile onSearch事件处理程序
在HTML5标准, <input type='search' onsearch='searchHandler()'>
但搜索事件没有被触发?
是因为我在手机中使用。
还有其他方法可以使用吗?
我正在使用jQuery Mobile的phoneGap在Android中创建应用程序。Jquery Mobile onSearch事件处理程序
在HTML5标准, <input type='search' onsearch='searchHandler()'>
但搜索事件没有被触发?
是因为我在手机中使用。
还有其他方法可以使用吗?
您可以绑定到change
事件,以确保您捕获搜索字符串的用户输入完成之后:
$('input[type="search"]').on('change', function (event) {
//the user has changed the value and de-focused the element or submitted the search
});
这里是一个演示:http://jsfiddle.net/w9Bdg/1/
注意.on()
是新的一样的jQuery 1.7,如果您使用的是旧版本,则与.bind()
相同。
坦率地说,我无法获得此代码和示例的用户行为。您在移动应用中拥有搜索字段。你可以在那里输入一些东西......以及如何激发这个事件?在PC上,我按下了“Enter”,但是如何在移动应用程序中触发此事件? – RredCat 2013-11-06 10:13:09
@RredCat当用户在搜索框外单击时,应该触发'change'事件。例如,如果他们点击一个“搜索”按钮,应该改变焦点元素并触发文本输入中的“更改”事件。你也可以绑定到按钮的'click'事件。 – Jasper 2013-11-06 15:56:39
我明白了。但在任何示例中,我都没有看到位置不错的搜索按钮。所以对我来说最好的办法就是'afterkeyup'事件。 – RredCat 2013-11-06 18:02:28