php學習筆記(JS中的常見方法)

來源:互聯網
上載者:User

標籤:nbsp   last   索引   bsp   常見   星期幾   數學   ceil   arc   

JS中的常見方法:

1.日期時間函數(需要用變數調用):
    var b = new Date(); //擷取目前時間
    b.getTime() //擷取時間戳記
    b.getFullYear() //擷取年份
    b.getMonth()+1; //擷取月份
    b.getDate() //擷取天
    b.getHours() //擷取小時
    b.getMinutes() //擷取分鐘
    b.getSeconds() //擷取秒數
    b.getDay() //擷取星期幾
    b.getMilliseconds() //擷取毫秒
    Date()  //擷取完整日期


2.數學函數(用Math來調用):
    abs(x)返回數的絕對值。
    ceil(x)對數進行上舍入。
    floor(x)對數進行下舍入。
    round(x)把數四捨五入為最接近的整數。
    max(x,y)返回 x 和 y 中的最高值。
    min(x,y)返回 x 和 y 中的最低值。
    pow(x,y)返回 x 的 y 次冪。
    sqrt(x)返回數的平方根。
    random()返回 0 ~ 1 之間的隨機數。 ****

    字串函數(用變數來調用):

    indexOf
    返回字串中一個子串第一處出現的索引(從左至右搜尋)。如果沒有匹配項,返回 -1 。
    var index1 = a.indexOf("l");
    //index1 = 2

    charAt 返回指定位置的字元。

    var get_char = a.charAt(0);
              //get_char = "h"

l    astIndexOf
    返回字串中一個子串最後一處出現的索引(從右至左搜尋),如果沒有匹配項,返回 -1 。
    var index1 = lastIndexOf(‘l‘);
    //index1 = 3


    match
    檢查一個字串匹配一個Regex內容,如果麼有匹配返回 null。
    var re = new RegExp(/^\w+$/);
    var is_alpha1 = a.match(re);
    //is_alpha1 = "hello"
    var is_alpha2 = b.match(re);
    //is_alpha2 = null

    substring
    返回字串的一個子串,傳入參數是起始位置和結束位置。

    var sub_string2 = a.substring(1,4);
    //sub_string2 = "ell"

    substr ********
    返回字串的一個子串,傳入參數是起始位置和長度
    var sub_string1 = a.substr(1);
    //sub_string1 = "ello"
    var sub_string2 = a.substr(1,4);
    //sub_string2 = "ello"

    replace *******
    替換字串,第一個參數代表被替換的字串,第二個參數代表替換的字串
    a.replace("he","aa")


    search
    執行一個Regex匹配尋找。如果尋找成功,返回字串中匹配的索引值。否則返回 -1 。
    var index1 = a.search(re);
    //index1 = 0
    var index2 = b.search(re);
    //index2 = -1

    split ******
    通過將字串劃分成子串,將一個字串做成一個字串數組。
    var arr1 = a.split("");
    //arr1 = [h,e,l,l,o]

    length 屬性 *******
    返回字串的長度,所謂字串的長度是指其包含的字元的個數。


    toLowerCase
    將整個字串轉成小寫字母。
    var lower_string = a.toLowerCase();
    //lower_string = "hello"

    toUpperCase
    將整個字串轉成大寫字母。
    var upper_string = a.toUpperCase();
    //upper_string = "HELLO"

 

php學習筆記(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.