日期:2014-05-17  浏览次数:20675 次

在HTML中使用JSValidate 例子

1.html源码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Content-Language" content="zh-cn">
<title>JavaScript Validation Framework</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script language="JavaScript" src="validation-framework.js"></script>
<SCRIPT LANGUAGE="JavaScript" src="site.js"></SCRIPT>
</head>

<body>

<br />

<table cellpadding="10" width="760" cellspacing="0" align="center" class="ContentTable">
<tr>
<td class="Nav" valign="top">
<br />
</td>
<td valign="top">

<script language="JavaScript" src="validation-framework.js"></script>

<div id="error" style="color:red;font-weight:bold"></div>
<form id="form2" name="form2" method="post" action="/webproject2/servlet/survey" onsubmit="return doValidate(this)">
  <table width="408" border="0">
    <tr>
      <th width="135" align="left" scope="col">姓名:</th>
      <th width="257" align="left" scope="col"><label>
        <input name="name" type="text" id="name" size="20" />
      </label></th>
    </tr>
    <tr>
      <th align="left" scope="row">E_mail地址:</th>
      <td align="left"><input name="email" type="text" id="email" size="40" /></td>
    </tr>
    <tr>
      <th height="26" align="left" scope="row">年龄:      </th>
      <td align="left"><label>
      <input type="radio" name="age" id="radio" value="18" />
      小于18
      <input name="age" type="radio" id="radio2" value="18-40" checked="checked" />
      18-40
      <input type="radio" name="age" id="radio3" value="40" />
      40以上
      </label></td>
    </tr>
    <tr>
      <th align="left" scope="row">编程时间:</th>
      <td align="left"><label>
        <select name="code" id="code">
          <option value="never">不编程</option>
          <option value="6" selected="selected">小于6个月</option>
          <option value="6-12">6个月到12个月</option>
          <option value="12-24">12-24个月</option>
          <option value="24">大于24个月</option>
                                                </select>
      </label></td>
    </tr>
    <tr>
      <th align="left" scope="row">熟悉操作系统:</th>
      <td align="left"><label>
        <select name="os" size="4" multiple="multiple" id="os">
          <option value="WinXP" selected="selected">WinXP</option>
          <option value="Win2000/2003">Win2000/2003</option>
          <option value="Mac OS">Mac OS</option>
          <option value="Linux">Linux</option>
                                                                                </select>
      </label></td>
    </tr>
    <tr>
      <th height="23" align="left" scope="row">编程语言:</th>
      <td align="left"><label>
        <input name="language" type="checkbox" id="language" value="Java" />
        Java
        <input name="language" type="checkbox" id="language" value="C" />
        C
        <input name="language" type="checkbox" id="language" value="C++" />
        C++
        <input name="language" type="checkbox" id="language" value="C#" />
        C#
        <input name="language" type="checkbox" id="language" value="VB" />
      VB</label></td>
    </tr>
    <tr>
      <th align="left" scope="row">