Android的JQuery的焦点()的解决方法

问题描述:

我正在一个HTML5移动应用程序(使用普通jQuery的,不是移动电话),它实现了将出现一个文本区域下方的自定义自动完成列表。用户从列表中选择一个选项,该字被自动完成,并且用户继续键入照常

I'm working on an HTML5 mobile app (using regular jQuery, not mobile), which implements a custom autocomplete list that appears below a textarea. The user selects an option from the list, the word is autocompleted, and the user continues typing as usual.

问题是,用户点击文本框以外的选择自动完成的项目,所以暂时的textarea失去焦点。由于焦点()在Android浏览器被关闭,我不能马上重新集中,并保留作为插入符的最后一个位置,我通常会。

The problem is that the user taps outside of the textbox to select an item from the autocomplete, so the textarea momentarily loses focus. Since focus() is deactivated in the android browser, I can't immediately re-focus and retain the caret's last position as I usually would.

有一种解决方法,使我重新专注于一个textarea,preserving插入位置作为常规模糊()和重点()的调用会吗?

Is there a workaround that would allow me to re-focus on a textarea, preserving caret position as regular blur() and focus() calls would?

编辑:
基本假设来源:这里所说: http://*.com/a/10243010/832607 并在这里:
http://ambrusmartin.word$p$pss.com/2012/08/30/soft-keyboards-in-android-iphone-phonegap-applications-when-we-call-focus/ (在链接中提到已经尝试过的解决方案)

Sources of underlying assumption: mentioned here: http://*.com/a/10243010/832607 and here: http://ambrusmartin.wordpress.com/2012/08/30/soft-keyboards-in-android-iphone-phonegap-applications-when-we-call-focus/ (Already tried solution mentioned in link)

而不是重新聚焦我建议想不输在首位的焦点textarea的。我实现这一目标时preventing上鼠标按下的默认操作。

Instead re-focusing the textarea I'd recommend trying to not lose the focus in the first place. I'm achieving this when preventing the default action on mousedown.

下面是jQuery的,假设列表是你的选项列表和所有选项都有 LISTEL 类:

Here is the jQuery, assuming list is your list of options and all options have listEl class:

list.on('mousedown', '.listEl', function(e) { 
  e.preventDefault(); 
});