如何让表单值消失

如何让表单值消失

本文介绍了当我进入该领域时,如何让表单值消失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个简单的表单,大约有八个输入字段。我希望现场的初始值能够表明人们应该进入的内容。例如value =name,这样人们就知道在那里输入那里的名字。

我的问题是,当他们进入该领域时,初始值如何才会消失,以便初始值只是一个提示而不是永久值删除之前,他们可以输入他们的名字?



谢谢!

解决方案

将默认值设置为名称。然后,使用JavaScript和'onfocus'事件,清除该字段。



所以你应该有:

 < input type =textboxvalue =Nameonfocus =if(this.value =='Name')this.value ='';/> 


I am making a simple form with about eight input fields. I want the initial value in the field to indicate what people are supposed to enter. For example value="name" so that people know to enter there name there.

My question though is how do you get the initial value to vanish when they enter that field so that the initial value is only a hint and not a permanent value that they have to erase before they can type in their name?

Thanks!

解决方案

Set the 'default' value to "Name". Then, using javascript and the 'onfocus' event, clear the field.

So you would have:

<input type="textbox" value="Name" onfocus="if (this.value=='Name') this.value='';"/>

这篇关于当我进入该领域时,如何让表单值消失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 23:25