当页面重新加载时,如何重置文本输入的值? [英] How do I reset the value of a text input when the page reloads?

查看:105
本文介绍了当页面重新加载时,如何重置文本输入的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firefox(甚至其他浏览器)希望保留用户在文本输入中输入的任何文本,即使在重新加载之后。只需在html中包含默认文本(我希望输入可以恢复为)不起作用:

 <输入tyep ='text'value ='default text'/> 

并非试图使用JS

  window.onload = function(){document.getElementById(mytextinput)。value ='default text'} 


设置<$ 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆