javascripte15

 

fontcolor(color)     ->指定使用某顏色<o:p></o:p>

fontsize(size)  ->指定使用某字級大小<o:p></o:p>

indexOf(搜尋值,[起始位置])<o:p></o:p>

              ->由左至右搜尋該字串第一次出現的位置<o:p></o:p>

lastIndexOf(搜尋值,[起始位置])<o:p></o:p>

              ->由右至左搜尋該字串第一次出現的位置<o:p></o:p>

字串物件可使用的方法如下。<o:p></o:p>

字串物件方法(3)<o:p></o:p>

replace(x,y)           ->用字串y 取代字串x<o:p></o:p>

toLowerCase()              ->轉換成小寫<o:p></o:p>

toUpperCase()        ->轉換成大寫<o:p></o:p>

charAt(index)         ->傳回索引值所指的字元<o:p></o:p>

substring(索引值A,索引值B)<o:p></o:p>

              ->傳回由索引值A至索引值B前一字元<o:p></o:p>

                  所構成的字串<o:p></o:p>

substr(索引值A, 字串長度)<o:p></o:p>

              ->傳回由索引值A開始的子字串<o:p></o:p>

字串物件可使用的方法如下。<o:p></o:p>

字串物件方法(4)<o:p></o:p>

slice(起始值 [, 結束值])<o:p></o:p>

              ->將字串從指定的字元位置開始, <o:p></o:p>

                 指定的位置結束, 摘錄成一新的字串<o:p></o:p>

split(“字元”)      ->將字串以指定之字元為單位, 切成<o:p></o:p>

                 數個子字串, 並存成陣列<o:p></o:p>

concat(字串2 [, 字串3])<o:p></o:p>

              ->將幾段字串結合成完整字串<o:p></o:p>

<Script><o:p></o:p>

<o:p> </o:p>

   var str   = "Hello!";<o:p></o:p>

   var num   = 12345;<o:p></o:p>

   var yahoo = "來去Yahoo";<o:p></o:p>

   with(document){<o:p></o:p>

      write(str.big(),"<BR>");<o:p></o:p>

      write(num.toString().bold(),"<BR>");<o:p></o:p>

      write(yahoo.link("http://tw.yahoo.com/"));<o:p></o:p>

   }<o:p></o:p>

<o:p> </o:p>

</Script><o:p></o:p>

字串物件範例一<o:p></o:p>

<Script><o:p></o:p>

<o:p> </o:p>

   var str1   = "10";<o:p></o:p>

   var str2   = "20";<o:p></o:p>

<o:p> </o:p>

   with(document){<o:p></o:p>

      write(str1 + str2,"<BR>");<o:p></o:p>

      write(Number(str1) + Number(str2),"<BR>");<o:p></o:p>

   }<o:p></o:p>

<o:p> </o:p>

</Script><o:p></o:p>

字串物件範例二<o:p></o:p>

<Script><o:p></o:p>

<o:p> </o:p>

   var sayHello = "你好嗎";<o:p></o:p>

<o:p> </o:p>

   document.write(sayHello.fontcolor("#ff00ff"), "<BR>");<o:p></o:p>

   document.write(sayHello.replace('',''));<o:p></o:p>

   document.write("共有", sayHello.length, "個字。<BR>");<o:p></o:p>

<o:p> </o:p>

</Script><o:p></o:p>

字串物件範例三<o:p></o:p>

<Script><o:p></o:p>

   var hello = "HELLO!"<o:p></o:p>

   with(document) {<o:p></o:p>

      write(hello,"<BR>")<o:p></o:p>

      write("1個字元為",hello.charAt(0),"<BR>")<o:p></o:p>

      write("L在第",hello.indexOf("L"),"個字元","<BR>")<o:p></o:p>

      write("L在第",hello.lastIndexOf("L"), "個字元","<BR>")<o:p></o:p>

      write("k在第",hello.indexOf("k"),"個字元","<BR>")<o:p></o:p>

      write(hello.fontsize("5"),"<BR>")<o:p></o:p>

      write("擷取第2至第4個字元:",hello.substring(1,4),"<BR>")<o:p></o:p>

      write("擷取從第2個字元開始的3個字元:",<o:p></o:p>

            hello.substr(1,3),"<BR>")<o:p></o:p>

   }<o:p></o:p>

<o:p> </o:p>

</Script><o:p></o:p>

字串物件範例四<o:p></o:p>

<Script><o:p></o:p>

   function isEmail() {<o:p></o:p>

      if (document.form1.text1.value == "")<o:p></o:p>

         alert("請填寫你的電子郵件地址。");<o:p></o:p>

      else if (document.form1.text1.value.indexOf("@") == -1)<o:p></o:p>

         alert("沒有\"@\"符號,不算電子郵件地址。");<o:p></o:p>

      else<o:p></o:p>

         alert("檢查完成!");<o:p></o:p>

   }<o:p></o:p>

</Script><o:p></o:p>

<form name="form1"><o:p></o:p>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值