请教版主一个简单JavaScript,谢谢
能够判断表单带“*”符号的必填项,拿到题目是这样的~~编写javascirpt脚本函数“CheckInput()”实现,能够判断表单带“*”符号的必填项“您的大名“内容是否为空,为空出现提示”请正确填写!“,不为空则提示“恭喜您!”。
为表单添加“onSubmit”事件时调用编写的“CheckInput()”脚本函数,实现单击“提交留言”按钮后对必填项的输入验证。
页面已经做好~~~就差表单验证,网页代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<link href="css/css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.STYLE1 {color: #FF0000}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /></head>
<body>
<table width="770" height="500" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="130" rowspan="2" bgcolor="#9CD339"> </td>
<td width="555" height="62" bgcolor="#9CD339"> </td>
</tr>
<tr>
<td align="center" valign="middle"><table width="640" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" valign="middle"><div class="css" id="message-top">留言板</div></td>
</tr>
<tr>
<td height="15"><hr /></td>
</tr>
<tr>
<td><div class="css2" id="message-main">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="25" align="center" valign="middle">请在此留言</td>
</tr>
<tr>
<td><form id="messsage Form" name="messsage Form" method="post" action="">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="38%" height="50" align="left">你的大名:
<label>
<input name="yourname" type="text" id="yourname" value="" size="18" />
<span class="STYLE1">*</span></label></td>
<td width="29%" align="left">QQ:
<label>
<input name="qqno" type="text" id="qqno" size="15" maxlength="20" />
</label></td>
<td width="33%" align="center">来自:
<label>
<input name="fromcity" type="text" id="fromcity" size="18" />
</label></td>
</tr>
<tr>
<td height="50" align="left">邮箱地址:
<input name="mailbox" type="text" id="mailbox" value="" size="20" /></td>
<td align="left">性别:
<select name="sex" size="1" id="sex">
<option>保密</option>
<option>男</option>
<option>女</option>
</select></td>
<td align="center"> </td>
</tr>
<tr>
<td height="50" colspan="2" align="left" valign="middle">主 页:
<label>
<input name="vebpage" type="text" id="vebpage" size="40" />
</label></td>
<td> </td>
</tr>
<tr>
<td height="100" colspan="3" align="center" valign="bottom">内容:
<label>
<textarea name="mesageinfo" cols="75" rows="6" id="mesageinfo"></textarea>
</label></td>
</tr>
<tr>
<td height="50"> </td>
<td align="center" valign="middle"><label>
<input type="submit" name="Submit" value="提交留言" />
</label></td>
<td> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</div></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
[ 本帖最后由 myland 于 2009-8-15 19:22 编辑 ]