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

Javascript
符合标准的对联广告
Firefox 无法获取cssRules 的解决办法
简单JS代码压缩器
不错的asp中显示新闻的功能
动态加载js文件 document.createElement
[原创]静态页面也可以实现预览 列表不同的显示方式
JS代码格式化和语法着色V2
关于javascript的“静态类"
显示/隐藏侧边栏
网页取色
cancelBubble阻止事件冒泡
屏蔽alt+f4代码,一个变通的方法
光标的一些操作总结
使用TextRange获取输入框中光标的位
Using the TextRange Object
textbox右键菜单
document.createRange实例
模仿IE自动完成功能
计算100000数组js脚本的执行时间
怎么让脚本或里面的函数在所有图片都载入完毕的时候执行

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


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

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