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 ;
}
}
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进行表单提交验证。表单采用post方法,action属性值为{* $action *},enctype为multipart/form-data,提交时调用check函数进行验证。

6433

被折叠的 条评论
为什么被折叠?



