函數submitForms()按submit按鈕後對字段合法性檢查後發送電子郵件
函數isName()對姓名字段進行合法性檢查
函數isEmail()對電子郵件地址字段進行合法性檢查
函數isBrowser()對浏覽器字段與自動檢測的浏覽器版本進行比較
函數isCountry()對國家字段進行合法性檢查
函數isComment()對意見字段進行合法性檢查
函數isFavorite()對喜歡的站點字段進行合法性檢查
程序中還提供了一些技巧
結果是以電子郵件的形式提供給你的
<HTML>
<HEAD>
<TITLE>用JavaScript編制留言簿程序</TITLE>
<SCRIPTLANGUAGE=
<!
//是你自己的電子郵件地址
varemailAddress=
functiontoName()
{
vartoNameval=document
toNameval=
this
}
functionReset(){
document
document
document
navigator
document
document
document
document
}
functionsubmitForms(){
if((isName())&&(isEmail())&&(isBrowser())
&&(isCountry())&&(isComment())&&(isFavorite()))
if(confirm(
onYEStosubmit
{
alert(
\n\n
returntrue;
}
else
{
alert(
returnfalse;
}
else
returnfalse;
}
functionisName(){
varstr=document
if(str==
alert(
document
returnfalse;
}
for(vari=
{
varch=str
if(((ch<
{
alert(
&spaces
document
document
returnfalse;
}
}
returntrue;
}
functionisEmail()
{
emailAddress=document
if(document
alert(
\n\nPleaseenteryoure
document
returnfalse;
}
if(document
document
{
alert(
anda\
document
document
returnfalse;
}
else
{
toName();
returntrue;
}
}
functionisBrowser()
{
if(document
=navigator
{
if(confirm(
type
n\nClickonCanceltorestoredetectedbrowser
returntrue
else
{
document
navigator
returntrue;
}
}
else
returntrue;
}
functionisCountry(){
varstr=document
if(str==
alert(
blank
document
returnfalse;
}
for(vari=
varch=str
if(((ch<
(ch<
{
alert(
letters&spaces
document
document
returnfalse;
}
}
returntrue;
}
functionisComment(){
if(document
if(confirm(
withoutleavingacomment
onCANCELtoincludeacomment
onOKtocontinuewithoutacomment
returntrue
else
{
document
returnfalse;
}
}
else
returntrue
}
functionisFavorite(){
if(document
if(confirm(
listingyourfavoritesites
toincludefavorites
withoutlistingfavorites
returntrue
else
{
document
returnfalse;
}
}
else
returntrue
}
//End
</SCRIPT>
</HEAD>
<BODY>
<CENTER>
<FORMENCTYPE=
NAME=
ACTION=
onSubmit=
<TABLEBORDER=
<TR>
<TDalign=
<STRONG>Enteryourname:</STRONG></FONT></TD>
<TDalign=
<STRONG>Enteryoure
</FONT></TD>
</TR>
<TR>
<TDalign=
NAME=
</TD>
<TDalign=
NAME=
</TR>
<TR>
<TDalign=
<STRONG>Yourbrowser</STRONG></FONT></TD>
<TDalign=
<STRONG>Enteryourcountry:</STRONG></FONT></TD>
</TR>
<TR>
<TDalign=
NAME=
<TDalign=
NAME=
</TD>
</TR>
</TABLE>
<CENTER>
<FONTCOLOR=
Leaveacommentorsuggestion:</strong></font><BR>
<TEXTAREANAME=
ROWS=
Suggestions?</TEXTAREA><P><P>
<FONTCOLOR=
Listyourfavoritesites:</STRONG></FONT><BR>
<TDalign=
ROWS=
AnysitesIshouldtakealookat?</TEXTAREA>
<P><P>
<INPUTTYPE=
<center><INPUTTYPE=
onClick=
</FORM>
</CENTER>
</BODY>
</HTML>
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19258.html