需要 HTML 文本区域标记帮助
我在文本区域中设置了默认值。我希望当有人单击文本区域时默认值消失。 HTML 代码是什么?
I have set a default value in textarea. I want that when someone clicks on the textarea the default value disappears. Whats the HTML code for that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您正在寻找 HTML5
placeholder
属性:这适用于所有较新的浏览器保存为 IE。要覆盖旧版浏览器,您可以使用填充程序
You are looking for the HTML5
placeholder
attribute:This will work on all newer browsers save for IE. To cover older browser, you can use a shim
您无法在 HTML 中执行此操作。为此,您必须使用 Javascript。所以像这样...
onfocus
属性将允许 Javascript 在文本框获得焦点后执行。 Javascript 检查文本是否是默认文本,如果是,它将清除文本框。You can't do this in HTML. You'll have to use Javascript for that. So something like this...
The
onfocus
property will allow the Javascript to execute once the textbox has focus. The Javascript checks to see if the text is the default and if it is, it will clear the textbox.尝试这个jQuery
在textarea标签中
或javascript:或者对于较新的浏览器,html5(也在textarea标签中):
或者将其带回来:
try this jQuery
or javascript inside the textarea tag:
or for newer browsers the html5 (also in the textarea tag):
or to bring it back:
这是负责的一小段代码:
基本上,当焦点事件被触发时,当前字段的值被设置为空字符串
""
当然,您可以使其更复杂并确保它仅当元素包含默认消息时才删除:
javascript:
this is the little piece of code responsible:
basically when the focus event is fired, the value of the current field is set to an empty string
""
of course you can make it more complexe and make sure it only erase when the element contains the default message:
javascript: