• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 幾個很有用的javascript函數

    發表于:2007-06-21來源:作者:點擊數: 標簽:
    函數Reset()按Reset按鈕后對各字段的內容復位。 函數submitForms()按submit按鈕后對字段合法性檢查后發送電子郵件。 函數isName()對姓名字段進行合法性檢查。 函數isEmail()對電子郵件地址字段進行合法性檢查。 函數isBrowser()對瀏覽器字段與自動檢測的瀏覽

       
      函數Reset()按Reset按鈕后對各字段的內容復位。

      函數submitForms()按submit按鈕后對字段合法性檢查后發送電子郵件。

      函數isName()對姓名字段進行合法性檢查。

      函數isEmail()對電子郵件地址字段進行合法性檢查。

      函數isBrowser()對瀏覽器字段與自動檢測的瀏覽器版本進行比較。

      函數isCountry()對國家字段進行合法性檢查。

      函數isComment()對意見字段進行合法性檢查,不允許為空值。

      函數isFavorite()對喜歡的站點字段進行合法性檢查,不允許為空值。

      程序中還提供了一些技巧,例如,如何判斷瀏覽器的版本,字符串的操作等等。

      結果是以電子郵件的形式提供給你的,里面有客人輸入的各個字段。程序比較長,但不難看懂,下面是源代碼:

    <HTML>

    <HEAD>

    <TITLE>用JavaScript編制留言簿程序</TITLE>

    <SCRIPTLANGUAGE="JavaScript">

    <!--Begin

    //Someone@abc.com是你自己的電子郵件地址

    varemailAddress="Someone@abc.com";

    functiontoName()

    {

    vartoNameval=document.forms[0].elements[1].value;

    toNameval="mailto:Someone@abc.com?subject=GuestBookexample";

    this.document.mail.action=toNameval;

    }

    functionReset(){

    document.forms[0].elements[0].value="";

    document.forms[0].elements[1].value="";

    document.forms[0].elements[2].value=

    navigator.appName+""+navigator.appVersion;

    document.forms[0].elements[3].value="";

    document.forms[0].elements[4].value="";

    document.forms[0].elements[5].value="";

    document.forms[0].elements[0].focus();

    }

    functionsubmitForms(){

    if((isName())&&(isEmail())&&(isBrowser())

    &&(isCountry())&&(isComment())&&(isFavorite()))

    if(confirm("\nYou'reabouttoe-mailtheform.\n\nClick

    onYEStosubmit.\n\nClickonNOtoabort."))

    {

    alert("\nYoursubmissionwillnowbemadeto:

    \n\n"+emailAddress+"\n\n\nThankyou!");

    returntrue;

    }

    else

    {

    alert("\nYouhavechosentoabortthesubmission.");

    returnfalse;

    }

    else

    returnfalse;

    }

    functionisName(){

    varstr=document.forms[0].elements[0].value;

    if(str==""){

    alert("\nTheNAMEfieldisblank.\n\nPleaseenteryourname.")

    document.forms[0].elements[0].focus();

    returnfalse;

    }

    for(vari=0;i<str.length;i++)

    {

    varch=str.substring(i,i+1);

    if(((ch<"a"||"z"<ch)&&(ch<"A"||"Z"<ch))&&ch!='')

    {

    alert("\nTheNAMEfieldonlyaclearcase/" target="_blank" >cceptsletters

    &spaces.\n\nPleasere-enteryourname.");

    document.forms[0].elements[0].select();

    document.forms[0].elements[0].focus();

    returnfalse;

    }

    }

    returntrue;

    }

    functionisEmail()

    {

    emailAddress=document.forms[0].elements[1].value;

    if(document.forms[0].elements[1].value==""){

    alert("\nTheE-MAILfieldisblank.

    \n\nPleaseenteryoure-mailaddress.")

    document.forms[0].elements[1].focus();

    returnfalse;

    }

    if(document.forms[0].elements[1].value.indexOf('@',0)==-1||

    document.forms[0].elements[1].value.indexOf('.',0)==-1)

    {

    alert("\nTheE-MAILfieldrequiresa\"@\"

    anda\".\"beused.\n\nPleasere-enteryoure-mailaddress.")

    document.forms[0].elements[1].select();

    document.forms[0].elements[1].focus();

    returnfalse;

    }

    else

    {

    toName();

    returntrue;

    }

    }

    functionisBrowser()

    {

    if(document.forms[0].elements[2].value!

    =navigator.appName+""+navigator.appVersion)

    {

    if(confirm("\nYou'vechangedyourbrowser

    type.\n\nClickonOKtokeepchanges.\

    n\nClickonCanceltorestoredetectedbrowser."))

    returntrue

    else

    {

    document.forms[0].elements[2].value=

    navigator.appName+""+navigator.appVersion;

    returntrue;

    }

    }

    else

    returntrue;

    }

    functionisCountry(){

    varstr=document.forms[0].elements[3].value;

    if(str==""){

    alert("\nTheCOUNTRYfieldis

    blank.\n\nPleaseenteryourcountry.")

    document.forms[0].elements[3].focus();

    returnfalse;

    }

    for(vari=0;i<str.length;i++){

    varch=str.substring(i,i+1);

    if(((ch<"a"||"z"<ch)&&

    (ch<"A"||"Z"<ch))&&ch!='')

    {

    alert("\nTheCOUNTRYfieldonlyaccepts

    letters&spaces.\n\nPleasere-enteryourcountry.");

    document.forms[0].elements[3].select();

    document.forms[0].elements[3].focus();

    returnfalse;

    }

    }

    returntrue;

    }

    functionisComment(){

    if(document.forms[0].elements[4].value==""){

    if(confirm("\nYou'reabouttosubmit

    withoutleavingacomment.\n\nClick

    onCANCELtoincludeacomment.\n\nClick

    onOKtocontinuewithoutacomment."))

    returntrue

    else

    {

    document.forms[0].elements[4].focus();

    returnfalse;

    }

    }

    else

    returntrue

    }

    functionisFavorite(){

    if(document.forms[0].elements[5].value==""){

    if(confirm("\nYou'reabouttosubmitwithout

    listingyourfavoritesites.\n\nClickonCANCEL

    toincludefavorites.\n\nClickonOKtocontinue

    withoutlistingfavorites."))

    returntrue

    else

    {

    document.forms[0].elements[5].focus();

    returnfalse;

    }

    }

    else

    returntrue

    }

    //End-->

    </SCRIPT>

    </HEAD>

    <BODY>

    <CENTER>

    <FORMENCTYPE="text/plain"

    NAME="mail"METHOD='GET'

    ACTION='mailto:Someone@abc.com'

    onSubmit="returnsubmitForms()">

    <TABLEBORDER=0WIDTH=400>

    <TR>

    <TDalign="center"><FONTCOLOR=800000>

    <STRONG>Enteryourname:</STRONG></FONT></TD>

    <TDalign="center"><FONTCOLOR=800000>

    <STRONG>Enteryoure-mailaddress:</STRONG>

    </FONT></TD>

    </TR>

    <TR>

    <TDalign="center"><INPUTTYPE="text"

    NAME="name"SIZE=30MAXLENGTH=40></TD>

    </TD>

    <TDalign="center"><INPUTTYPE="text"

    NAME="email"SIZE=30MAXLENGTH=40></TD>

    </TR>

    <TR>

    <TDalign="center"><FONTCOLOR=800000>

    <STRONG>Yourbrowser</STRONG></FONT></TD>

    <TDalign="center"><FONTCOLOR=800000>

    <STRONG>Enteryourcountry:</STRONG></FONT></TD>

    </TR>

    <TR>

    <TDalign="center"><INPUTTYPE="text"

    NAME="browser"SIZE=30MAXLENGTH=60></TD>

    <TDalign="center"><INPUTTYPE="text"

    NAME="country"SIZE=30MAXLENGTH=60>

    </TD>

    </TR>

    </TABLE>

    <CENTER>

    <FONTCOLOR=800000><STRONG>

    Leaveacommentorsuggestion:</strong></font><BR>

    <TEXTAREANAME="comments"

    ROWS=5COLS=50wrap=yes>Comments?

    Suggestions?</TEXTAREA><P><P>

    <FONTCOLOR=800000><STRONG>

    Listyourfavoritesites:</STRONG></FONT><BR>

    <TDalign="center"><TEXTAREANAME="favorites"

    ROWS=5COLS=50wrap=yes>

    AnysitesIshouldtakealookat?</TEXTAREA>

    <P><P>

    <INPUTTYPE="submit"VALUE="Submit">

    <center><INPUTTYPE="reset"VALUE="Reset"

    onClick="Reset()">

    </FORM>

    </CENTER>

    </BODY>

    </HTML>

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>