您的位置:首页 > Web前端 > JavaScript

简单javascript验证 外加焦点改变

2005-02-04 16:09 267 查看
 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> 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  javascript action function