Javascript - Replace html using innerHTML

前端 未结 2 1788
-上瘾入骨i
-上瘾入骨i 2020-12-16 14:28

I\'m trying to replace html using innerHTML javascript.

From:

aaaaaa/cat/bbbbbb

To:



        
2条回答
  •  执笔经年
    2020-12-16 15:23

    You should chain the replace() together instead of assigning the result and replacing again.

    var strMessage1 = document.getElementById("element1") ;
    strMessage1.innerHTML = strMessage1.innerHTML
                            .replace(/aaaaaa./g,'Helloworld');
    

    See DEMO.

提交回复
热议问题