<script type="text/javascript"> var oBox=document.getElementById('box'); var oBtn=document.getElementById('btn'); var oP=document.getElementsByTagName('p')[0]; oBtn.onclick=function(){ var val=document.getElementById('tel').value; var reg=/^1[345678]\d{9}$/; if (val=='') { oP.style.color="red"; oP.innerHTML="请输入手机号!"; }else if(reg.test(val)){ oP.style.color="green"; oP.innerHTML="输入正确!"; }else{ oP.style.color="red"; oP.innerHTML="输入错误,请重新输入!"; } } </script> </body> </html>