点击HTML字段中的文字消失? [英] Text in HTML Field to disappear when clicked?

查看:171
本文介绍了点击HTML字段中的文字消失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以轻松地创建一个已经包含文本的html输入字段。但是,当用户点击输入字段时,文本不会消失,而是停留在那里。用户然后必须手动删除要键入的文本。我怎样才能创建一个输入字段,当用户点击输入框时文本消失?

要做的是使用HTML5属性 placeholder ,它可以让您为输入框设置默认值:

< input type =textname =inputBoxplaceholder =在此输入您的文字>



应该达到你想要的。但是,请小心,因为Internet Explorer 9和更早版本不支持占位符属性。


I can easily create a html input field that has text already in it. But when the user clicks on the input field the text doesn't disappears but stays there. The user then has to manually remove the text to type. How can I create an input field where when the user clicks on the input field box the text then disappear?

解决方案

What you want to do is use the HTML5 attribute placeholder which lets you set a default value for your input box:

<input type="text" name="inputBox" placeholder="enter your text here">

This should achieve what you're looking for. However, be careful because the placeholder attribute is not supported in Internet Explorer 9 and earlier versions.

这篇关于点击HTML字段中的文字消失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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