在html5中input,textarea等元素新添加了placeholder的属性,我们可以通过css设置placeholder的样式,对于ie,firefox,以及webkit内核的浏览器需要使用不同的样式写法。
如下测试代码:
<html>
<head>
<style type = "text/css" >
#myInput::-webkit-input-placeholder { color : red ; }
#myInput:-moz-placeholder { color : red ; }
#myInput:-ms-input-placeholder { color : red ; }
</style>
</head>
<body>
<input id = 'myInput' placeholder = 'hello' />
<br>
<textarea id = 'myInput' placeholder = 'hello' ></textarea>
</body>
</html>