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

Javascript
在js中使用"with"语句中跨frame的变量引用问题
原型方法的不同写法居然会影响调试的解决方法
在JavaScript中遭遇级联表达式陷阱
JScript内置对象Array中元素的删除方法
获取JavaScript用户自定义类的类名称的代码
使用TextRange获取输入框中光标的位置的代码
使用onbeforeunload属性后的副作用
IE7提供XMLHttpRequest对象为兼容
encode脚本和normal脚本混用的问题与解决方法
用js判断用户浏览器是否是XP SP2的IE6
关于使用runtimeStyle属性问题讨论文章
javascript学习随笔(使用window和frame)的技巧
javascript学习随笔(编写浏览器脚本 Navigator Scripting )
跑马灯效果大全
让超链接显示提示信息的js代码
打开超链需要“确认”对话框的方法
javascript的对话框详解与参数
让网页上的超链接失效,不能点击的js代码
鼠标经过时链接文字的特别震撼的显示效果
显示页面的所有链接的js代码

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


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

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