js替换最后一次出现的匹配的字符串
var v = "abbbabbbbab"; var pos = v.lastIndexOf("a"); var vv = v.substring(0, pos) + "c" + v.substring(pos+1, v.length); alert(vv);
js直接替换第一次出现的匹配字符串
var str = "adksdjfldjfoeoxl"; var t = str.lastIndexOf("d"); str = str.replace(/d/, "c"); alert(str);
时间: 2024-10-07 04:50:29