linux社区爱心援助Linux认证系列教程业界动态站务新闻公司招聘网络学院网址大全LPI专题CISCO专题
设为首页
加入收藏
管理团队
JSP  
JAVA  
PERL  
 您的位置:首页 > 开发语言 > JavaScript >
栏目导栏
  php
  JSP
  ASP
  asp.net
  JAVA
  c/c++/c#
  perl
  JavaScript
  Basic
  Delphi
资料搜索
热门文章
·javascript 时间对象的格式化
·去掉字符串前后的空格
·javascript 事件监听机制
·javascript 事件调用顺序
·js刷新框架子页面的七种方法
·JavaScript:替换字符串
·IE下的JScript编程需注意的内存
·用javascript操作word文档
·Javascript中CTRL+回车提交表单
·JS 获取鼠标位置
·javascript判断Email地址是否有
·Javascript中Select的OnChange
·JS实现的滑动展开与折叠效果
·有分页功能的WEB打印
·Javascript实现窗口最大化的严
最新文章
·使用CSS改变表格边框样式
·为网页添加浮动广告
·判断表单中添加是否数字的JS与
·让浏览器状态栏动起来
·使用Javascript制作行间颜色间
·禁止用右键查看源代码
·网页侦测四法
·制作弹出公告窗口
·为网页添加特效
·网页中取消鼠标右键方法大全
·JavaScript 根据屏幕解析度显示
·如何实现浏览器上的右键菜单
·如何制作浮动广告
·让弹出窗口变得“体贴”一些
·JavaScript技巧:让网页自动穿上
Google
 
几个很有用的javascript函数
[ 作者:  加入时间:2008-02-20 18:38:57  来自:Linux联盟收集整理 ]
函数Reset()按Reset按钮后对各字段的内容复位。Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
  函数submitForms()按submit按钮后对字段合法性检查后发送电子邮件。Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
  函数isName()对姓名字段进行合法性检查。Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
  函数isEmail()对电子邮件地址字段进行合法性检查。Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
  函数isBrowser()对浏览器字段与自动检测的浏览器版本进行比较。Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
  函数isCountry()对国家字段进行合法性检查。Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
  函数isComment()对意见字段进行合法性检查,不允许为空值。Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
  函数isFavorite()对喜欢的站点字段进行合法性检查,不允许为空值。Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
  程序中还提供了一些技巧,例如,如何判断浏览器的版本,字符串的操作等等。Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
  结果是以电子邮件的形式提供给你的,里面有客人输入的各个字段。程序比较长,但不难看懂,下面是源代码:Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
<HTML>Jy3Linux联盟
Jy3Linux联盟
<HEAD>Jy3Linux联盟
Jy3Linux联盟
<TITLE>用JavaScript编制留言簿程序</TITLE>Jy3Linux联盟
Jy3Linux联盟
<SCRIPTLANGUAGE="JavaScript">Jy3Linux联盟
Jy3Linux联盟
<!--BeginJy3Linux联盟
Jy3Linux联盟
//Someone@abc.com是你自己的电子邮件地址Jy3Linux联盟
Jy3Linux联盟
varemailAddress="Someone@abc.com";Jy3Linux联盟
Jy3Linux联盟
functiontoName()Jy3Linux联盟
Jy3Linux联盟
{Jy3Linux联盟
Jy3Linux联盟
vartoNameval=document.forms[0].elements[1].value;Jy3Linux联盟
Jy3Linux联盟
toNameval="mailto:Someone@abc.com?subject=GuestBookexample";Jy3Linux联盟
Jy3Linux联盟
this.document.mail.action=toNameval;Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
functionReset(){Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[0].value="";Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[1].value="";Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[2].value=Jy3Linux联盟
Jy3Linux联盟
navigator.appName+""+navigator.appVersion;Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[3].value="";Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[4].value="";Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[5].value="";Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[0].focus();Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
functionsubmitForms(){Jy3Linux联盟
Jy3Linux联盟
if((isName())&&(isEmail())&&(isBrowser())Jy3Linux联盟
Jy3Linux联盟
&&(isCountry())&&(isComment())&&(isFavorite()))Jy3Linux联盟
Jy3Linux联盟
if(confirm("\nYou'reabouttoe-mailtheform.\n\nClickJy3Linux联盟
Jy3Linux联盟
onYEStosubmit.\n\nClickonNOtoabort."))Jy3Linux联盟
Jy3Linux联盟
{Jy3Linux联盟
Jy3Linux联盟
alert("\nYoursubmissionwillnowbemadeto:Jy3Linux联盟
Jy3Linux联盟
\n\n"+emailAddress+"\n\n\nThankyou!");Jy3Linux联盟
Jy3Linux联盟
returntrue;Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
elseJy3Linux联盟
Jy3Linux联盟
{Jy3Linux联盟
Jy3Linux联盟
alert("\nYouhavechosentoabortthesubmission.");Jy3Linux联盟
Jy3Linux联盟
returnfalse;Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
elseJy3Linux联盟
Jy3Linux联盟
returnfalse;Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
functionisName(){Jy3Linux联盟
Jy3Linux联盟
varstr=document.forms[0].elements[0].value;Jy3Linux联盟
Jy3Linux联盟
if(str==""){Jy3Linux联盟
Jy3Linux联盟
alert("\nTheNAMEfieldisblank.\n\nPleaseenteryourname.")Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[0].focus();Jy3Linux联盟
Jy3Linux联盟
returnfalse;Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
for(vari=0;i<str.length;i++)Jy3Linux联盟
Jy3Linux联盟
{Jy3Linux联盟
Jy3Linux联盟
varch=str.substring(i,i+1);Jy3Linux联盟
Jy3Linux联盟
if(((ch<"a"||"z"<ch)&&(ch<"A"||"Z"<ch))&&ch!='')Jy3Linux联盟
Jy3Linux联盟
{Jy3Linux联盟
Jy3Linux联盟
alert("\nTheNAMEfieldonlyacceptslettersJy3Linux联盟
Jy3Linux联盟
&spaces.\n\nPleasere-enteryourname.");Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[0].select();Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[0].focus();Jy3Linux联盟
Jy3Linux联盟
returnfalse;Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
returntrue;Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
functionisEmail()Jy3Linux联盟
Jy3Linux联盟
{Jy3Linux联盟
Jy3Linux联盟
emailAddress=document.forms[0].elements[1].value;Jy3Linux联盟
Jy3Linux联盟
if(document.forms[0].elements[1].value==""){Jy3Linux联盟
Jy3Linux联盟
alert("\nTheE-MAILfieldisblank.Jy3Linux联盟
Jy3Linux联盟
\n\nPleaseenteryoure-mailaddress.")Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[1].focus();Jy3Linux联盟
Jy3Linux联盟
returnfalse;Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
if(document.forms[0].elements[1].value.indexOf('@',0)==-1||Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[1].value.indexOf('.',0)==-1)Jy3Linux联盟
Jy3Linux联盟
{Jy3Linux联盟
Jy3Linux联盟
alert("\nTheE-MAILfieldrequiresa\"@\"Jy3Linux联盟
Jy3Linux联盟
anda\".\"beused.\n\nPleasere-enteryoure-mailaddress.")Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[1].select();Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[1].focus();Jy3Linux联盟
Jy3Linux联盟
returnfalse;Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
elseJy3Linux联盟
Jy3Linux联盟
{Jy3Linux联盟
Jy3Linux联盟
toName();Jy3Linux联盟
Jy3Linux联盟
returntrue;Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
functionisBrowser()Jy3Linux联盟
Jy3Linux联盟
{Jy3Linux联盟
Jy3Linux联盟
if(document.forms[0].elements[2].value!Jy3Linux联盟
Jy3Linux联盟
=navigator.appName+""+navigator.appVersion)Jy3Linux联盟
Jy3Linux联盟
{Jy3Linux联盟
Jy3Linux联盟
if(confirm("\nYou'vechangedyourbrowserJy3Linux联盟
Jy3Linux联盟
type.\n\nClickonOKtokeepchanges.\Jy3Linux联盟
Jy3Linux联盟
n\nClickonCanceltorestoredetectedbrowser."))Jy3Linux联盟
Jy3Linux联盟
returntrueJy3Linux联盟
Jy3Linux联盟
elseJy3Linux联盟
Jy3Linux联盟
{Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[2].value=Jy3Linux联盟
Jy3Linux联盟
navigator.appName+""+navigator.appVersion;Jy3Linux联盟
Jy3Linux联盟
returntrue;Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
elseJy3Linux联盟
Jy3Linux联盟
returntrue;Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
functionisCountry(){Jy3Linux联盟
Jy3Linux联盟
varstr=document.forms[0].elements[3].value;Jy3Linux联盟
Jy3Linux联盟
if(str==""){Jy3Linux联盟
Jy3Linux联盟
alert("\nTheCOUNTRYfieldisJy3Linux联盟
Jy3Linux联盟
blank.\n\nPleaseenteryourcountry.")Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[3].focus();Jy3Linux联盟
Jy3Linux联盟
returnfalse;Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
for(vari=0;i<str.length;i++){Jy3Linux联盟
Jy3Linux联盟
varch=str.substring(i,i+1);Jy3Linux联盟
Jy3Linux联盟
if(((ch<"a"||"z"<ch)&&Jy3Linux联盟
Jy3Linux联盟
(ch<"A"||"Z"<ch))&&ch!='')Jy3Linux联盟
Jy3Linux联盟
{Jy3Linux联盟
Jy3Linux联盟
alert("\nTheCOUNTRYfieldonlyacceptsJy3Linux联盟
Jy3Linux联盟
letters&spaces.\n\nPleasere-enteryourcountry.");Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[3].select();Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[3].focus();Jy3Linux联盟
Jy3Linux联盟
returnfalse;Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
returntrue;Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
functionisComment(){Jy3Linux联盟
Jy3Linux联盟
if(document.forms[0].elements[4].value==""){Jy3Linux联盟
Jy3Linux联盟
if(confirm("\nYou'reabouttosubmitJy3Linux联盟
Jy3Linux联盟
withoutleavingacomment.\n\nClickJy3Linux联盟
Jy3Linux联盟
onCANCELtoincludeacomment.\n\nClickJy3Linux联盟
Jy3Linux联盟
onOKtocontinuewithoutacomment."))Jy3Linux联盟
Jy3Linux联盟
returntrueJy3Linux联盟
Jy3Linux联盟
elseJy3Linux联盟
Jy3Linux联盟
{Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[4].focus();Jy3Linux联盟
Jy3Linux联盟
returnfalse;Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
elseJy3Linux联盟
Jy3Linux联盟
returntrueJy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
functionisFavorite(){Jy3Linux联盟
Jy3Linux联盟
if(document.forms[0].elements[5].value==""){Jy3Linux联盟
Jy3Linux联盟
if(confirm("\nYou'reabouttosubmitwithoutJy3Linux联盟
Jy3Linux联盟
listingyourfavoritesites.\n\nClickonCANCELJy3Linux联盟
Jy3Linux联盟
toincludefavorites.\n\nClickonOKtocontinueJy3Linux联盟
Jy3Linux联盟
withoutlistingfavorites."))Jy3Linux联盟
Jy3Linux联盟
returntrueJy3Linux联盟
Jy3Linux联盟
elseJy3Linux联盟
Jy3Linux联盟
{Jy3Linux联盟
Jy3Linux联盟
document.forms[0].elements[5].focus();Jy3Linux联盟
Jy3Linux联盟
returnfalse;Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
elseJy3Linux联盟
Jy3Linux联盟
returntrueJy3Linux联盟
Jy3Linux联盟
}Jy3Linux联盟
Jy3Linux联盟
//End-->Jy3Linux联盟
Jy3Linux联盟
</SCRIPT>Jy3Linux联盟
Jy3Linux联盟
</HEAD>Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
Jy3Linux联盟
<BODY>Jy3Linux联盟
Jy3Linux联盟
<CENTER>Jy3Linux联盟
Jy3Linux联盟
<FORMENCTYPE="text/plain"Jy3Linux联盟
Jy3Linux联盟
NAME="mail"METHOD='GET'Jy3Linux联盟
Jy3Linux联盟
ACTION='mailto:Someone@abc.com'Jy3Linux联盟
Jy3Linux联盟
onSubmit="returnsubmitForms()">Jy3Linux联盟
Jy3Linux联盟
<TABLEBORDER=0WIDTH=400>Jy3Linux联盟
Jy3Linux联盟
<TR>Jy3Linux联盟
Jy3Linux联盟
<TDalign="center"><FONTCOLOR=800000>Jy3Linux联盟
Jy3Linux联盟
<STRONG>Enteryourname:</STRONG></FONT></TD>Jy3Linux联盟
Jy3Linux联盟
<TDalign="center"><FONTCOLOR=800000>Jy3Linux联盟
Jy3Linux联盟
<STRONG>Enteryoure-mailaddress:</STRONG>Jy3Linux联盟
Jy3Linux联盟
</FONT></TD>Jy3Linux联盟
Jy3Linux联盟
</TR>Jy3Linux联盟
Jy3Linux联盟
<TR>Jy3Linux联盟
Jy3Linux联盟
<TDalign="center"><INPUTTYPE="text"Jy3Linux联盟
Jy3Linux联盟
NAME="name"SIZE=30MAXLENGTH=40></TD>Jy3Linux联盟
Jy3Linux联盟
</TD>Jy3Linux联盟
Jy3Linux联盟
<TDalign="center"><INPUTTYPE="text"Jy3Linux联盟
Jy3Linux联盟
NAME="email"SIZE=30MAXLENGTH=40></TD>Jy3Linux联盟
Jy3Linux联盟
</TR>Jy3Linux联盟
Jy3Linux联盟
<TR>Jy3Linux联盟
Jy3Linux联盟
<TDalign="center"><FONTCOLOR=800000>Jy3Linux联盟
Jy3Linux联盟
<STRONG>Yourbrowser</STRONG></FONT></TD>Jy3Linux联盟
Jy3Linux联盟
<TDalign="center"><FONTCOLOR=800000>Jy3Linux联盟
Jy3Linux联盟
<STRONG>Enteryourcountry:</STRONG></FONT></TD>Jy3Linux联盟
Jy3Linux联盟
</TR>Jy3Linux联盟
Jy3Linux联盟
<TR>Jy3Linux联盟
Jy3Linux联盟
<TDalign="center"><INPUTTYPE="text"Jy3Linux联盟
Jy3Linux联盟
NAME="browser"SIZE=30MAXLENGTH=60></TD>Jy3Linux联盟
Jy3Linux联盟
<TDalign="center"><INPUTTYPE="text"Jy3Linux联盟
Jy3Linux联盟
NAME="country"SIZE=30MAXLENGTH=60>Jy3Linux联盟
Jy3Linux联盟
</TD>Jy3Linux联盟
Jy3Linux联盟
</TR>Jy3Linux联盟
Jy3Linux联盟
</TABLE>Jy3Linux联盟
Jy3Linux联盟
<CENTER>Jy3Linux联盟
Jy3Linux联盟
<FONTCOLOR=800000><STRONG>Jy3Linux联盟
Jy3Linux联盟
Leaveacommentorsuggestion:</strong></font><BR>Jy3Linux联盟
Jy3Linux联盟
<TEXTAREANAME="comments"Jy3Linux联盟
Jy3Linux联盟
ROWS=5COLS=50wrap=yes>Comments?Jy3Linux联盟
Jy3Linux联盟
Suggestions?</TEXTAREA><P><P>Jy3Linux联盟
Jy3Linux联盟
<FONTCOLOR=800000><STRONG>Jy3Linux联盟
Jy3Linux联盟
Listyourfavoritesites:</STRONG></FONT><BR>Jy3Linux联盟
Jy3Linux联盟
<TDalign="center"><TEXTAREANAME="favorites"Jy3Linux联盟
Jy3Linux联盟
ROWS=5COLS=50wrap=yes>Jy3Linux联盟
Jy3Linux联盟
AnysitesIshouldtakealookat?</TEXTAREA>Jy3Linux联盟
Jy3Linux联盟
<P><P>Jy3Linux联盟
Jy3Linux联盟
<INPUTTYPE="submit"VALUE="Submit">Jy3Linux联盟
Jy3Linux联盟
<center><INPUTTYPE="reset"VALUE="Reset"Jy3Linux联盟
Jy3Linux联盟
onClick="Reset()">Jy3Linux联盟
Jy3Linux联盟
</FORM>Jy3Linux联盟
Jy3Linux联盟
</CENTER>Jy3Linux联盟
Jy3Linux联盟
</BODY>Jy3Linux联盟
Jy3Linux联盟
</HTML> Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·常用的Javascript函数  (2007-11-23 13:45:44)
 ·Javascript函数 判断数字的合法性  (2007-11-15 12:21:34)