1.使用占位符placeholder。但是这个在chrome不是很好用。使用过bootstrap框架的人肯定都很了解
<input type="text" placeholder="please input your name" >
如图所示:
2.如果需要提示的内容比较长,我们不应该一直使用placeholder属性,我们可以使用title属性,在移动到输入框上出现提示内容,代码如下:
<input type="text" title="请输入姓名">
3.为了在聚焦的时候更改样式,则可以通过:
input:focus{
background: red;
}
4.有时候我们需要在打开页面的时候就自动对焦,这时候可以使使用autofocus,如下:
<input type="text" autofocus >
5.是否需要在第二次输入的时候自动提示,如果是on,那么就是需要提示,off则不需要提示,代码如下:
<form action="#" Autocomplete="on">
<input type="text">
<input type="text">
<input type="text" Autocomplete="off">
<input type="submit">
</form>
<input type="text" required>
如果不填写内容,在提交的时候回出现如下所示:
7.在测试的时候或者在后台测试数据的时候,我们需要关闭验证,可以在加上一个novalidate,如下所示:
<form action="#" novalidate>
</form>