当页面重新加载时,如何重置文本输入的值? [英] How do I reset the value of a text input when the page reloads?
本文介绍了当页面重新加载时,如何重置文本输入的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<输入tyep ='text'value ='default text'/>
并非试图使用JS
window.onload = function(){document.getElementById(mytextinput)。value ='default text'}
$ p $您可以使用普通的旧HTML :)
设置<$ c <$ c
$ div <
< input type ='text'中的$ c> autocomplete ='off'
value ='default text'autocomplete ='off'/>
这适用于大多数现代浏览器。
Firefox (and probably other browsers) want to keep whatever text the user entered in the text input, even after a reload. Just including the default text (that I want the input to revert to) in the html doesn't work:
<input tyep='text' value='default text' />
And neither does trying to use JS
window.onload = function() {document.getElementById("mytextinput").value = 'default text'}
解决方案You can use plain old HTML :)
Set
autocomplete='off'
in the attribute<input type='text' value='default text' autocomplete='off' />
This works on most modern browsers.
这篇关于当页面重新加载时,如何重置文本输入的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文