当前位置: 首页 > 图文教程 > 网络编程 > Javascript > javascript进行客户端数据的校验

Javascript
快速判断某个值是否在select中的方法
js-穷举法 (y0h)
彪哥1.1(智能表格)提供下载
prototype 1.5 & scriptaculous 1.6.1 学习笔记
IE中jscript/javascript的条件编译
prototype class详解
Javascript 事件捕获的备忘(setCapture,captureEvents)
showModelessDialog()使用详解
Mozilla中显示textarea中选择的文字
加入收藏夹代码(兼容 gecko)
b/s开发常用javaScript技术
一些有关检查数据的JS代码
Javascript 不能释放内存.
多附件上传组件演示
一个很Cool的JS菜单效果
打造个性化的Select(可编辑)
真正的连续滚动图片
js常用函数 不错
document.getElementById的一些细节
由浅到深了解JavaScript类

Javascript 中的 javascript进行客户端数据的校验


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-10   浏览: 163 ::
收藏到网摘: n/a

//作者:叨叨
//email:[email protected]
//客户端对用户输入数据校验
//如果输入的内容不满足,则不提交,并且焦点自动跳到该位置。
//比发送以后在服务器端校验数据要好用的多!

脚本代码:

<script language="JavaScript">
<!--
function Juge(theForm)
{

if (theForm.title.value == "")
{
alert("请输入标题!");
theForm.title.focus();
return (false);
}
if (theForm.detail.value == "")
{
alert("请输入内容!");
theForm.detail.focus();
return (false);
}
if (theForm.name.value == "")
{
alert("请输入作者!");
theForm.name.focus();
return (false);
}
if (theForm.email.value == "")
{
alert("请输入信箱!");
theForm.email.focus();
return (false);
}

}

-->
</script>



html网页代码:

<html>
<head>
<title>文章发布</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body bgcolor=#fafee9>
<center>原创文章投稿处</center>
<br><center><font color=red>此处严禁发表转载或者抄袭的文章!</font></center>
<form name="form1" method="post" action="pub_ok.php" onsubmit="javascript:return Juge(this);" >
<table width="90%" border="0" cellspacing="1" cellpadding="1" align="center">
<tr>
<td>
您的姓名:<input type=text name=name size=30>
</td>
</tr>
<tr>
<td>
您的信箱:<input type=text name=email size=30>
</td>
</tr>
<tr>
<td>
文章标题:<input type="text" name=title size="50">
</td>
</tr>

<tr>
<td>
文章内容:<br><textarea name=detail style="width=80%;height=180px;"></textarea>
</td>
</tr>
<tr>
<td>
一些说明:<br><textarea name=demo style="width=80%;height=80px;"></textarea>
</td>
</tr>
<tr>
<td><input type="submit" name="pub" value="发布您的作品"></td>
</tr>
</table>
</form>
<p>
</body>
</html>

//取自我网站的原创文学发布页面。