1

在 jQuery Mobile 中有过滤的列表视图。将文本输入过滤器后,列表会被过滤,但按 GO 按钮不会隐藏键盘。

用户希望键盘在按下 GO 后会隐藏。有没有办法做到这一点?

4

3 回答 3

1

您必须使用 Javascript 手动从输入字段中移除焦点,如下所示:

$('.ui-listview-filter .ui-input-text').live('keyup', function(event) {
    if (event.keyCode == 13) {
        // 'Go' pressed
        $('.ui-listview-filter .ui-input-text').trigger('blur');
    }
});
于 2012-08-10T09:36:35.827 回答
0

您可能想在按下键后尝试更改焦点。例如:

//this will un-select the text box, hiding keyboard
$('#searchInputId').blur();

//this will focus on something else, hiding keyboard
$('#somethingOtherThanTheSearch').focus();
于 2012-08-10T09:36:20.847 回答
0

Pablo 答案的变体适用于我过时的 jQuery(移动)版本:

  // this is here to close the on-screen keyboards of mobile devices when the "go" button is used
  $("input[data-type='search']").on('keyup', function(event) {
    if (event.keyCode == 13) { // Enter or 'Go' pressed
      event.target.blur(); // remove focus on the search field so keyboard goes away
    }
 });
于 2016-01-04T16:54:24.710 回答