JavaScript函数中的拆分和替换

JavaScript函数中的拆分和替换,javascript,string,function,replace,split,Javascript,String,Function,Replace,Split,我正在尝试拆分一个字符串,并在 使用JavaScipt函数的字符串。我的职责如下 <script> function test(table, col) { var table = document.getElementById(table); for (x = 1; x < table.rows.length; x++) { var temp = table.rows[x].cells[col].innerHTML; table.

我正在尝试拆分一个字符串,并在 使用JavaScipt函数的字符串。我的职责如下

<script>
function test(table, col) {
    var table = document.getElementById(table);
    for (x = 1; x < table.rows.length; x++) {
        var temp = table.rows[x].cells[col].innerHTML;
        table.rows[x].cells[col].innerHTML = .replace('P', 'B');
    }
}
</script>

功能测试(表、列){
var table=document.getElementById(表);
对于(x=1;x
因此将传递以下字符串
http://ff00.00--p.yos.local:3042/htmltemps/newtest.html
和 我期待这个结果:
http://ff00.00--b.yos.local:3042/htmltemps/newtest.html
。但我明白了:
b/htmltemps/newtest.html
。任何帮助都将被告知

var str = "http://ff00.00--p.yos.local:3042/htmltemps/newtest.html";
var res = str.replace("--p", "--b");

注意:不需要使用split()。

使用带有不区分大小写标志的RegExo对象
i

函数替换文本(tableId,columnIndex){
var table=document.getElementById(tableId);
Array.prototype.forEach.call(table.rows,function(row){
变量单元格=行单元格[列索引];
cell.innerHTML=cell.innerHTML.replace(新的RegExp(“P”,“gim”),“b”);
});
}
替换文本('表',0)

http://ff00.00--p.yos.local:3042/htmltemps/newtest.html
http://ff00.02--p.yos.local:3042/htmltemps/newtest2.html

应该是
temp.replace('P','B')