标签:
第一种:(文本框获取焦点后,它的颜色会有所变化,当失去焦点的时候,恢复为原来的样子)
<html> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <script type="text/javascript" src="jquery-1.11.3.js"></script> <style type="text/css"> input:focus ,textarea:focus{ border: 1px solid #f00; background: #fcc; } </style> <body> <form action="#" method="POST" id="regForm"> <fieldset> <legend>个人基本信息</legend> <div> <label for="username">名称:</label> <input id="username" type="text"> </div> <div> <label for="pass">密码:</label> <input id="pass" type="password"> </div> <div> <label for="msg">详细信息:</label> <textarea id="msg"></textarea> </div> </fieldset> </form> </body> </html>
只不过IE中不兼容
第二种IE兼容:
1 <html> 2 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 3 <script type="text/javascript" src="jquery-1.11.3.js"></script> 4 <style type="text/css"> 5 6 .focus{ 7 border: 1px solid #f00; 8 background: #fcc; 9 } 10 </style> 11 <script type="text/javascript"> 12 $(function(){ 13 $(":input").focus(function(){ 14 $(this).addClass("focus") 15 }).blur(function(){ 16 $(this).removeClass("focus"); 17 }) 18 }) 19 20 </script> 21 <body> 22 <form action="#" method="POST" id="regForm"> 23 <fieldset> 24 <legend>个人基本信息</legend> 25 <div> 26 <label for="username">名称:</label> 27 <input id="username" type="text"> 28 </div> 29 <div> 30 <label for="pass">密码:</label> 31 <input id="pass" type="password"> 32 </div> 33 <div> 34 <label for="msg">详细信息:</label> 35 <textarea id="msg"></textarea> 36 </div> 37 38 </fieldset> 39 </form> 40 41 </body> 42 </html>
标签:
原文地址:http://www.cnblogs.com/adaonling/p/5214252.html