HTML 文本框输入工具提示?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7576733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML Textbox Input Tooltip?
提问by ivantxo
Possible Duplicate:
How do I make an HTML text box show a hint when empty?
可能的重复:
如何使 HTML 文本框在空时显示提示?
A very simple question. I would like to place a tooltip within a Textbox similar to the StackOverflow log in. I want the word discount on the textbox value and when the user enters a new value, the word "discount" disappears from the Textbox.
一个很简单的问题。我想在类似于 StackOverflow 登录的文本框中放置一个工具提示。我想要文本框值上的折扣一词,并且当用户输入新值时,“折扣”一词从文本框中消失。
Can I do this by myself using events like OnBlur, OnChange, etc (I don't know which)? Or there is something around that is already done?
我可以自己使用 OnBlur、OnChange 等事件(我不知道是哪个)来做到这一点吗?或者周围已经完成了一些事情?
Thanks
谢谢
回答by Simon Arnold
As said by rudeovski, you can use placeholder in modern browsers.
But for the older one, you'll need a javascript/jQuery fallback.
Here is a good example:
正如rudeovski 所说,您可以在现代浏览器中使用占位符。
但是对于较旧的,您将需要一个 javascript/jQuery 回退。
这是一个很好的例子:
http://uniquemethod.com/html5-placeholder-text-with-modernizr-and-jquery-fallback
http://uniquemethod.com/html5-placeholder-text-with-modernizr-and-jquery-fallback
This will generate placeholder fallback for you automaticly.
You simply have to write:
这将自动为您生成占位符回退。
你只需要写:
<input type="text" id="discount" placeholder="discount" />
Modernizrcombined with jQuerywill do the rest for you.
Hope this help :)
Modernizr结合jQuery将为您完成剩下的工作。
希望这有帮助:)
回答by mnsr
You can use placeholder text for this.
您可以为此使用占位符文本。
<input type="text" id="discount" placeholder="discount" />
To make it work on all browsers, you need to use jquery/javascript for it. As far as i know, it doesn't work in IE.
要使其适用于所有浏览器,您需要使用 jquery/javascript。据我所知,它在 IE 中不起作用。