default:比如多选框,页面刷新时,默认选择触发
indeterminate:比如多选框,都没选时的样式

1 <html> 2 <head> 3 <script> 4 function radio_onchange() 5 { 6 7 var radio = document.getElementById("radio1"); 8 var text = document.getElementById("text1"); 9 console.log(text.disabled); 10 if(radio.checked){ 11 console.log("checked"); 12 text.disabled = ""; 13 }else{ 14 console.log("unchecked"); 15 text.value = ""; 16 text.disabled = "disabled"; 17 } 18 } 19 </script> 20 <style type="text/css"> 21 input[type="text"]:enabled{ 22 background-color:yellow; 23 } 24 input[type="text"]:disabled{ 25 background-color:purple; 26 } 27 input[type="text"]:hover{ 28 background-color:skyblue; 29 } 30 input[type="text"]:focus{ 31 background-color:red; 32 } 33 input[type="text"]:read-only{ 34 background-color:gray; 35 } 36 37 input[type="checkbox"]:checked{ 38 outline:2px solid blue; 39 } 40 41 input[type="checkbox"]:indeterminate{ 42 outline:2px solid red; 43 } 44 </style> 45 </head> 46 <body> 47 <form> 48 <input type="radio" id="radio1" name="radio" onchange="radio_onchange();">可用</radio> 49 <input type="radio" id="radio2" name="radio" onchange="radio_onchange();">不可用</radio><br/> 50 <input type=text id="text1" disabled /> 51 <p> 52 姓名:<input type="text" name="name" /><br/> 53 Email:<input type="text" name="email" value="http://www.cnblogs.com/xing901022/" readonly="readonly" /> 54 </p> 55 56 兴趣:<input type="checkbox">阅读</input> 57 <input type="checkbox">电影</input> 58 <input type="checkbox">游戏</input> 59 <input type="checkbox">上网</input> 60 <br/> 61 62 63 </form> 64 </body> 65 </html>
invalid:不符合元素范围的
valid:符合元素范围校验的

1 <html> 2 <head> 3 <style type="text/css"> 4 input[type="text"]:invalid{ 5 background-color:red; 6 } 7 input[type="text"]:valid{ 8 background-color:white; 9 } 10 </style> 11 </head> 12 <body> 13 <form> 14 <p>必须输入文字:<input type="text" required /></p> 15 </form> 16 </body> 17 </html>
不合法时
合法时
required:支持这个属性,并且定义了required的
optional:支持requried属性,但是没有定义的

1 <html> 2 <head> 3 <style type="text/css"> 4 input[type="text"]:required{ 5 border-color:red; 6 border-width:3px; 7 } 8 input[type="text"]:optional{ 9 border-color:blue; 10 border-width:3px; 11 } 12 </style> 13 </head> 14 <body> 15 <form> 16 姓名:<input type="text" required placeholder="必须输入" /><br/> 17 年龄:<input type="text" /> 18 </form> 19 </body> 20 </html>
in-range:在范围内的
out-of-range:超出范围的

1 <html> 2 <head> 3 <style type="text/css"> 4 input[type="number"]:in-range{ 5 background-color:white; 6 } 7 input[type="number"]:out-of-range{ 8 background-color:red; 9 } 10 </style> 11 </head> 12 <body> 13 test number 1-100<input type=number min=0 max=100> 14 </body> 15 </html>
正常范围时
超出范围时
from:
http://www.cnblogs.com/xing901022/p/3971202.html
default:比如多选框,页面刷新时,默认选择触发
indeterminate:比如多选框,都没选时的样式

1 <html> 2 <head> 3 <script> 4 function radio_onchange() 5 { 6 7 var radio = document.getElementById("radio1"); 8 var text = document.getElementById("text1"); 9 console.log(text.disabled); 10 if(radio.checked){ 11 console.log("checked"); 12 text.disabled = ""; 13 }else{ 14 console.log("unchecked"); 15 text.value = ""; 16 text.disabled = "disabled"; 17 } 18 } 19 </script> 20 <style type="text/css"> 21 input[type="text"]:enabled{ 22 background-color:yellow; 23 } 24 input[type="text"]:disabled{ 25 background-color:purple; 26 } 27 input[type="text"]:hover{ 28 background-color:skyblue; 29 } 30 input[type="text"]:focus{ 31 background-color:red; 32 } 33 input[type="text"]:read-only{ 34 background-color:gray; 35 } 36 37 input[type="checkbox"]:checked{ 38 outline:2px solid blue; 39 } 40 41 input[type="checkbox"]:indeterminate{ 42 outline:2px solid red; 43 } 44 </style> 45 </head> 46 <body> 47 <form> 48 <input type="radio" id="radio1" name="radio" onchange="radio_onchange();">可用</radio> 49 <input type="radio" id="radio2" name="radio" onchange="radio_onchange();">不可用</radio><br/> 50 <input type=text id="text1" disabled /> 51 <p> 52 姓名:<input type="text" name="name" /><br/> 53 Email:<input type="text" name="email" value="http://www.cnblogs.com/xing901022/" readonly="readonly" /> 54 </p> 55 56 兴趣:<input type="checkbox">阅读</input> 57 <input type="checkbox">电影</input> 58 <input type="checkbox">游戏</input> 59 <input type="checkbox">上网</input> 60 <br/> 61 62 63 </form> 64 </body> 65 </html>
invalid:不符合元素范围的
valid:符合元素范围校验的

1 <html> 2 <head> 3 <style type="text/css"> 4 input[type="text"]:invalid{ 5 background-color:red; 6 } 7 input[type="text"]:valid{ 8 background-color:white; 9 } 10 </style> 11 </head> 12 <body> 13 <form> 14 <p>必须输入文字:<input type="text" required /></p> 15 </form> 16 </body> 17 </html>
不合法时
合法时
required:支持这个属性,并且定义了required的
optional:支持requried属性,但是没有定义的

1 <html> 2 <head> 3 <style type="text/css"> 4 input[type="text"]:required{ 5 border-color:red; 6 border-width:3px; 7 } 8 input[type="text"]:optional{ 9 border-color:blue; 10 border-width:3px; 11 } 12 </style> 13 </head> 14 <body> 15 <form> 16 姓名:<input type="text" required placeholder="必须输入" /><br/> 17 年龄:<input type="text" /> 18 </form> 19 </body> 20 </html>
in-range:在范围内的
out-of-range:超出范围的

1 <html> 2 <head> 3 <style type="text/css"> 4 input[type="number"]:in-range{ 5 background-color:white; 6 } 7 input[type="number"]:out-of-range{ 8 background-color:red; 9 } 10 </style> 11 </head> 12 <body> 13 test number 1-100<input type=number min=0 max=100> 14 </body> 15 </html>
正常范围时
超出范围时