js字符串替換

字號(hào):


    <script>
    function check()
    {var tempstr
    tempstr=ReplaceAll(document.form.temp.value,",","*")
    alert(tempstr);
    }
    function ReplaceAll(str, sptr, sptr1)
    {
    while (str.indexOf(sptr) >= 0)
    {
    str = str.replace(sptr, sptr1);
    }
    return str;
    }
    </script>
    <form onsubmit="check();" name="form">
    <input type="text" size="58" name="temp"/>
    <input type="submit" value="asdf" />
    </form>