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

Javascript
js中几种去掉字串左右空格的方法
判断两种颜色值是否为相似颜色
关于键盘事件中keyCode、which和charCode 的兼容性测试
提高 DHTML 页面性能
漂亮的Slider效果类终于封装成功
注释的艺术——JS里直接写HTML,无需转义
用javascript实现无刷新更新数据的详细步骤 asp
Windows Live的@live.com域名注册漏洞 利用代码
只能输入小于最大数且是正整数的脚本
破除网页鼠标右键被禁用的绝招大全
escape、encodeURI、encodeURIComponent等方法的区别比较
URL编码转换,escape() encodeURI() encodeURIComponent()
使用javascript访问XML数据的实例
ie和firefox中img对象区别的困惑
utf8的编码算法 转载
Javascript六种风格的时间显示方式
JavaScript实现禁止后退的方法
从javascript语言本身谈项目实战
通用于ie和firefox的函数 GetCurrentStyle (obj, prop)
javascript实现划词标记划词搜索功能修正版

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


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

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