当我进入该字段时,如何让表单值消失? [英] How do I get form values to disappear when I enter the field?

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

问题描述

我正在制作一个包含大约八个输入字段的简单表单.我希望字段中的初始值指示人们应该输入的内容.例如 value="name" 以便人们知道在那里输入名称.

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?

谢谢!

推荐答案

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

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

所以你会:

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

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

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