2017-05-30 69 views
0

我使用“ENTER”键提交了javascript的<form>并调用函数。该函数返回false以便页面不被重新加载。Chrome提示的框在提交后未被清除

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

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

下面是代码使用

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

尝试用'$( 'input.user')空()'。 – prasanth

+0

这仅仅是Chrome的一个建议框,还是框中的值? – Miles07

+0

我认为这从镀铬的建议来了...做一件事转到隐身模式,并检查了该建议来不来 对于隐身模式对铬: Ctrl + Shift + N为Windows 为Cmd + Shift + N为Mac –

回答

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; 
}); 
+0

完美。在我的Chrome上,我甚至不需要setTimeout,但我认为保持它更清洁。 –