jsreplace使用

字號:


    在js替換字符串當中遇到的一個問題:
    var tempdate="1999-9-9";
    //當用js的replace替換時出現(xiàn)問題
    alert(tempdate.replace("-","/"));
    //彈出的結果是1999/9-9,并沒有把全部的"-"替換掉,經(jīng)過網(wǎng)絡查詢,找出解決方法
    alert(tempdate.replace(/-/g,"/"));
    這樣替換成功!結果為1999/9/9