提交后,Chrome建议的框不会被清除

时间:2017-05-30 09:07:33

标签: javascript jquery html

我使用'ENTER'键在javascript中提交<form>并调用函数。此函数返回false,以便不重新加载页面。

不幸的是,该框未被清除,如图所示。

I have just added the 'tot' player at列表的末尾,但提出了't​​oto'和其他条目。建议框未清除。 我怎么能清除它?

以下是使用的代码

$('form').on('submit', function () {
    var newUser = $('input.user').val()
    displayPerson(newUser) // add the person
    $('input.user').val('')
    return false;
});

1 个答案:

答案 0 :(得分:2)

我建议简单地从输入中删除焦点:

$('form').on('submit', function () {
    var newUser = $('input.user').val()
    displayPerson(newUser) // add the person
    $('input.user').val('').blur(); // <-- blur
    setTimeout(function () { // Allow time for blur to happen
        $('input.user').focus(); // <-- put focus back (if desired).
    }, 0);
    return false;
});
相关问题