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

Javascript
[JS源码]超长文章自动分页(客户端版)
注意 JavaScript 中 RegExp 对象的 test 方法
JavaScript快速排序
写的一段拖动对象的代码
用js取得鼠标所在位置的对象
如何在一段文字里点一下就可以在里面插入一段文字?
用js+cookie记录滚动条位置
记录滚动条位置(使用userdate)
强效、方便的表单通用检测JS 不错
个人总结的一些关于String、Function、Array的属性和用法
数据排序谁最快(javascript中的Array.prototype.sort PK 快速排序)
Prototype最新版(1.5 rc2)使用指南(1)
Prototype使用指南之string.js
Prototype使用指南之base.js
Prototype使用指南之enumerable.js
Prototype使用指南之array.js
Prototype使用指南之range.js
Prototype使用指南之ajax
Prototype使用指南之dom.js
Prototype使用指南之selector.js

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-10   浏览: 214 ::
收藏到网摘: 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>

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