js中內建對象

來源:互聯網
上載者:User

標籤:html   javascript   

JavaScript charAt() 函數string.charAt(n) -- 返回指定位置(n)的字元
  • char是character的縮寫,中文"符號,字元"
  • 引用網址:http://www.dreamdu.com/javascript/string.charAt/
charAt函數文法
string.charAt(n);

charAt函數參數
  • n -- 字元在字串中的位置(字串第一個字元的位置為0)
charAt函數返回值
  • 返回n位置的字元

  • 如果n不在0到string.length-1之間,將返回Null 字元串
  • JavaScript indexOf() 函數string.indexOf(substring, startpos) -- 返回substring在string中的位置
    • index,中文"索引"
    • 引用網址:http://www.dreamdu.com/javascript/string.indexOf/
    indexOf函數文法
    string.indexOf(substring, startpos);
    indexOf函數參數
    • substring -- 要尋找的子字串
    • startpos -- 選擇性參數,從string的startpos位置開始尋找substring,如果沒有此參數將從string的開始位置尋找
    indexOf函數返回值
    • 返回子字串substring在字串string中的位置
    • 沒有在字串string中尋找到子字串substring,返回-1
    • JavaScript lastIndexOf() 函數string.lastIndexOf(substring, startpos) -- 返回substring在string中最後匹配(出現)的位置
      • last,中文"最後的,末尾的"
      • 引用網址:http://www.dreamdu.com/javascript/string.lastIndexOf/
      lastIndexOf函數文法
      string.lastIndexOf(substring, startpos);

      lastIndexOf函數參數
      • substring -- 要尋找的子字串
      • startpos -- 選擇性參數,從string的startpos位置開始尋找substring,如果沒有此參數將從string的開始位置尋找
      lastIndexOf函數返回值
      • 返回子字串substring在字串string中最後匹配的位置
      • 沒有在字串string中尋找到子字串substring,返回-1
      <html><body><script language="JavaScript" type="text/javascript">var myString="Welcome to Wrox books. ";myString=myString+"The Wrox website is www.Wrox.com. ";myString=myString+"visit the Wrox website today.";var foundAtPosition=0;var wroxCount=0;while(foundAtPosition !=-1){foundAtPosition=myString.indexOf("Wrox",foundAtPosition);if(foundAtPosition!=-1){wroxCount++;foundAtPosition++;}}document.write("there are+"wroxCount"+"occurrences of the word Wrox");</script></body></html>

      JavaScript substring() 函數string.substring(startPos, endPos) -- 返回從string的startPos位置,到endPos位置的字串
      • substring,中文"子字串"
      • 引用網址:http://www.dreamdu.com/javascript/string.substring/
      substring函數文法
      string.substring(startPos, endPos);

      substring函數參數
      • startPos -- 開始位置
      • endPos -- 結束位置
      substring函數返回值

      字串

      JavaScript substr() 函數string.substr(startPos, length) -- 返回從string的startPos位置,長度為length的字串
      • 不符合ECMA標準,不贊成使用.
      • substr,中文"子字串"
      • 引用網址:http://www.dreamdu.com/javascript/string.substr/
      substr函數文法
      string.substr(startPos, length);

      substr函數參數
      • startPos -- 開始位置(取負數時,從字串的結尾計算)
      • length -- 長度
      substr函數返回值

      字串

      JavaScript toLowerCase() 函數string.toLowerCase() -- 返回小寫字串
      • LowerCase,中文"小寫"
      • 引用網址:http://www.dreamdu.com/javascript/string.toLowerCase/
      toLowerCase函數文法
      string.toLowerCase();

      toLowerCase函數返回值

      返回小寫字串

      JavaScript toUpperCase() 函數string.toUpperCase() -- 返回大寫字串
      • UpperCase,中文"大寫"
      • 引用網址:http://www.dreamdu.com/javascript/string.toUpperCase/
      toUpperCase函數文法
      string.toUpperCase();

      toUpperCase函數返回值

      大寫字串

      toUpperCase函數樣本
      var str = "www.dreamdu.com";document.write(str.toUpperCase());

      結果:

      WWW.DREAMDU.COM


js中內建對象

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.