简单javascript验证 外加焦点改变

来源:互联网 发布:java程序员培训班 编辑:程序博客网 时间:2024/05/01 11:27
 function check(){
 if (document.news.title.value == "") {
 alert ("请输入标题名") ;
 document.news.title.focus() ; //set focus
 return false ;
 }
 if (document.news.username.value == ""){
 alert ("请输入你的用户名称") ;
 document.news.username.focus() ;
 return false ;
 }
 if (document.news.password.value == "") {
 alert ("请输入您的密码") ;
 document.news.password.focus() ;
 return false ;
 }
 if (document.news.authortype.value == "0") {
 alert ("选择单位") ;
 document.news.authortype.focus() ;
 return false ;
 }
 if (document.news.newstype.value == "0") {
 alert ("选择类别") ;
 document.news.newstype.focus() ;
 return false ;
 }
}

 

调用:

<form name="news" method="post" action="{* $action *}" enctype="multipart/form-data"
 onSubmit="return check();"> </form>