| 以下是引用片段: <script language=javascript> <!-- //Power by xiaotian 2002 function checkSubmit() { if ((document.form1.name.value)=='') { window.alert ('姓名必须填写'); document.form1.name.select(); document.form1.name.focus(); return false; } else return true; } //--> </script> <form name="form1" > <input type="text" name="name"> </form> |
| 以下是引用片段: <% Response.Write "<script language=javascript>"&vbCrlf&_ "<!--"&vbCrlf&_ "//Power by xiaotian 2002"&vbCrlf&_ "function checkSubmit()"&vbCrlf&_ "{"&vbCrlf&_ "if ((document.form1.name.value)=='')"&vbCrlf&_ "{"&vbCrlf&_ "window.alert ('姓名必须填写');"&vbCrlf&_ "document.form1.name.select();"&vbCrlf&_ "document.form1.name.focus();"&vbCrlf&_ "return false;"&vbCrlf&_ "else"&vbCrlf&_ "return true;"&vbCrlf&_ "}"&vbCrlf&_ "//-->"&vbCrlf&_ "</script>"&vbCrlf&_ %> |
| 以下是引用片段: Function findJS(frmName,errStr) Dim tmpArr Dim i '参数值 i=0 '获取错误列表,建立数组 tmpArr=Split(errStr,"│") '输出查询条件 Select Case tmpArr(i+1) Case "0" '必填的Text类型 findJS="if ((document."&frmName&"."&tmpArr(i)&".value)=="""")"&vbCrlf&_ "{"&vbCrlf&_ "window.alert ('"&tmpArr(i+2)&"');"&vbCrlf&_ "document."&frmName&"."&tmpArr(i)&".select();"&vbCrlf&_ "document."&frmName&"."&tmpArr(i)&".focus();"&vbCrlf&_ "return false;"&vbCrlf&_ "}"&vbCrlf '"else"&vbCrlf&_ '"return true;"&vbCrlf Exit Function Case "1" '必填的ListMenu类型 findJS="if ((document."&frmName&"."&tmpArr(i)&".value)=="""")"&vbCrlf&_ "{"&vbCrlf&_ "window.alert ('"&tmpArr(i+2)&"');"&vbCrlf&_ "document."&frmName&"."&tmpArr(i)&".focus();"&vbCrlf&_ "return false;"&vbCrlf&_ "}"&vbCrlf '"else"&vbCrlf&_ '"return true;"&vbCrlf Exit Function Case "2" '必须为数字的Text类型 findJS="if (isNaN(document."&frmName&"."&tmpArr(i)&".value))"&vbCrlf&_ "{"&vbCrlf&_ "window.alert ('"&tmpArr(i+2)&"');"&vbCrlf&_ "document."&frmName&"."&tmpArr(i)&".select();"&vbCrlf&_ "document."&frmName&"."&tmpArr(i)&".focus();"&vbCrlf&_ "return false;"&vbCrlf&_ "}"&vbCrlf '"else"&vbCrlf&_ '"return true;"&vbCrlf Exit Function Case "3" '必须为指定位数的Text类型 findJS="if (document."&frmName&"."&tmpArr(i)&".value.length="&tmpArr(i+3)&")"&vbCrlf&_ "{"&vbCrlf&_ "window.alert ('"&tmpArr(i+2)&"');"&vbCrlf&_ "document."&frmName&"."&tmpArr(i)&".select();"&vbCrlf&_ "document."&frmName&"."&tmpArr(i)&".focus();"&vbCrlf&_ "return false;"&vbCrlf&_ "}"&vbCrlf '"else"&vbCrlf&_ '"return true;"&vbCrlf Exit Function Case "4" '必须大于指定位数的Text类型 findJS="if (document."&frmName&"."&tmpArr(i)&".value.length<"&tmpArr(i+3)&")"&vbCrlf&_ "{"&vbCrlf&_ "window.alert ('"&tmpArr(i+2)&"');"&vbCrlf&_ "document."&frmName&"."&tmpArr(i)&".select();"&vbCrlf&_ "document."&frmName&"."&tmpArr(i)&".focus();"&vbCrlf&_ "return false;"&vbCrlf&_ "}"&vbCrlf '"else"&vbCrlf&_ '"return true;"&vbCrlf Exit Function Case "5" '必须为Email的Text类型 findJS="if ((!emailReg.test(document."&frmName&"."&tmpArr(i)&".value))&&(document."&frmName&"."&tmpArr(i)&".value!=''))"&vbCrlf&_ "{"&vbCrlf&_ "window.alert ('"&tmpArr(i+2)&"');"&vbCrlf&_ "document."&frmName&"."&tmpArr(i)&".select();"&vbCrlf&_ "document."&frmName&"."&tmpArr(i)&".focus();"&vbCrlf&_ "return false;"&vbCrlf&_ "}"&vbCrlf '"else"&vbCrlf&_ '"return true;"&vbCrlf Exit Function Case "6" '必须为a-z或0-9的字符的Text类型 findJS="if ((!pwdReg.test(document."&frmName&"."&tmpArr(i)&".value))&&(document."&frmName&"."&tmpArr(i)&".value!=''))"&vbCrlf&_ "{"&vbCrlf&_ "window.alert ('"&tmpArr(i+2)&"');"&vbCrlf&_ "document."&frmName&"."&tmpArr(i)&".select();"&vbCrlf&_ "document."&frmName&"."&tmpArr(i)&".focus();"&vbCrlf&_ "return false;"&vbCrlf&_ "}"&vbCrlf '"else"&vbCrlf&_ '"return true;"&vbCrlf Exit Function Case "7" '确认密码和密码必须相等的Text类型 findJS="if ((document."&frmName&"."&tmpArr(i)&".value)!=(document."&frmName&"."&tmpArr(i+3)&".value))"&vbCrlf&_ "{"&vbCrlf&_ "window.alert ('"&tmpArr(i+2)&"');"&vbCrlf&_ "document."&frmName&"."&tmpArr(i)&".select();"&vbCrlf&_ "document."&frmName&"."&tmpArr(i)&".focus();"&vbCrlf&_ "return false;"&vbCrlf&_ "}"&vbCrlf '"else"&vbCrlf&_ '"return true;"&vbCrlf Exit Function End Select End Function |
| 以下是引用片段: Sub CheckForm_JS(frmName,errStr) Dim tmpArr Dim i Dim strShow '输出JS的字符串 '获取错误列表,建立数组 tmpArr=Split(errStr,",") '写JS for i=0 to UBound(tmpArr) if i<>0 then strShow=strShow&"else "&findJS(frmName,tmpArr(i)) else strShow=strShow&findJS(frmName,tmpArr(i)) end if next '输出 strShow="<script language=javascript>"&vbCrlf&_ "<!--"&vbCrlf&_ "//Power by xiaotian 2002"&vbCrlf&_ "function checkSubmit()"&vbCrlf&_ "{"&vbCrlf&_ "var emailReg = /^[_a-z0-9]+@([_a-z0-9]+\.)+[a-z0-9]{2,3}$/;"&vbCrlf&_ "var pwdReg = /[a-z0-9]$/;"&vbCrlf&_ strShow&_ "else"&vbCrlf&_ "return true;"&vbCrlf&_ "}"&vbCrlf&_ "//-->"&vbCrlf&_ "</script>" Response.Write strShow End Sub |
| 以下是引用片段: if i<>0 then strShow=strShow&"else "&findJS(frmName,tmpArr(i)) else strShow=strShow&findJS(frmName,tmpArr(i)) end if |
| 以下是引用片段: "var emailReg = /^[_a-z0-9]+@([_a-z0-9]+\.)+[a-z0-9]{2,3}$/;"&vbCrlf&_ "var pwdReg = /[a-z0-9]$/;"&vbCrlf&_ |
| 以下是引用片段: <!--#include file="checkform_js.asp" --> <% Call checkform_js("frm","name│0│姓名必须填写,number│2│编号必须是数字,number│3│编号指定为6位数│6,email│5│email的格式不正确") %> <form name="frm" > 姓名:<input type="text" name="name"> 编号:<input type="text" name="number"> email:<input type="text" name="email"> <input type="submit" name="submit" value="提交"> </form> |
| 以下是引用片段: <% Dim errStr errStr="name│0│姓名必须填写,"&_ "number│2│编号必须是数字,number│3│编号指定为6位数│6,"&_ "email│5│email的格式不正确" Call checkform_js("frm",errStr) %> |
| 以下是引用片段: <script language=javascript> <!-- //Power by xiaotian 2002 function checkSubmit() { var emailReg = /^[_a-z0-9]+@([_a-z0-9]+\.)+[a-z0-9]{2,3}$/; var pwdReg = /[_a-z0-9]$/; if ((document.frm.name.value)=="") { window.alert ('姓名必须填写'); document.frm.name.select(); document.frm.name.focus(); return false; } else if (isNaN(document.frm.number.value)) { window.alert ('编号必须是数字'); document.frm.number.select(); document.frm.number.focus(); return false; } else if (document.frm.number.value.length=6) { window.alert ('编号指定为6位数'); document.frm.number.select(); document.frm.number.focus(); return false; } else if ((!emailReg.test(document.frm.email.value))&&(document.frm.email.value!='')) { window.alert ('email的格式不正确'); document.frm.email.select(); document.frm.email.focus(); return false; } else return true; } //--> </script> |