设置输入的占位符样式,我该怎么做?

20 html css html5 input placeholder

可能重复:
使用CSS更改输入的HTML5占位符颜色

例如,我有这个:

<input type='search' placeholder='Search' name='q' />
Run Code Online (Sandbox Code Playgroud)

如何用CSS设置占位符的样式?默认情况下它是灰色的,但我希望它是黑色的.我必须使用JavaScript吗?

mat*_*hew 14

没有标准的方法,并不是每个浏览器都支持占位符.

像这样的东西应该这样做:

/* prefix with input if you want, but this will catch input and texatrea */
  ::-webkit-input-placeholder {  color: #000;}
  :-moz-placeholder { color: #000; }
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/CHG46/

如果你想让旧的和新的浏览器支持占位符(IE6-9),似乎有一个jquery插件,这里有一个, https://github.com/mathiasbynens/Placeholder-jQuery-Plugin 但是,我还没有以前用过它.