Javascript前端验证

简单非空验证

demo:添加博客,标题不为空

hint:Struts的html:form标签生成的html标签那么属性为newsForm

JavaScript:

<mce:script language="javascript"><!-- function on_submit() {//验证数据的合法性 if (newsForm.title.value == "") { alert("标题不能为空!"); newsForm.title.focus(); return false; } return true; } // --></mce:script>

 

form表单:

<html:form action="/news.do?method=addNews" onsubmit="return on_submit()"> <table> <tr> <td align="center" bgcolor=#e6e6fa colspan=2 nowrap> <b><font color=blue face=楷体_GB2312 size=5>发表博客</font> </b> </TD> </TR> <tr> <td align="center" bgcolor=#e6e6fa colspan=2 nowrap> <b><font color=balck face=楷体_GB2312 size=5>标题 *<html:text property="title" size="50" /> <html:errors property="title" /> </font> </b> </TD> </TR> <tr> <td noWrap width="45%"> <div align=left> <table bgcolor=#d5e8fd border=0 cellspacing=1 width="100%"> <tr> <td align="center"> <FCK:editor instanceName="main" height="400pt" /> <br /> <input type="submit" name="button" value="提交内容" /> <input type="reset" name="button1" value="重写" /> </td> </tr> </table> </div> </table> </html:form>

你可能感兴趣的:(Javascript前端验证)