js的onfocus,onblur事件
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <label for="txt">姓名:</label> <input id="txt" type="text"> <span id="action"></span> </body> <script type="text/javascript"> var txt=document.getElementById("txt"); txt.onfocus=function(){ //友好提示 var span=document.getElementById("action"); span.innerHTML="用户格式最小8位"; span.style.color="#0f0"; }; txt.onblur=function(){ var span=document.getElementById("action"); span.innerHTML="对不起,格式不正确"; span.style.color="#f00"; } </script> </html>