0
我試圖取代像HTML標籤中使用新文本的文本:的Javascript無法與HTML與新文本替換文本
text = " hello how are you? " ;
newText = "<h1>hello how are you? </h1> " ;
這是我的代碼:
//replacer holds the html element
var replacer = document.getElementById("#"+id);
var newElement = "<span style='font-size:100px;' id='one4'>"+selectedinnerText+"</span>";
//selectedinnerText holds the text to be replaced
alert(selectedinnerText + " "+ newElement );
//This below line is not working properly
replacer.innerHTML = replacer.innerHTML.replace(selectedinnerText,newElement);
在調試器,設置一個斷點在'VAR replacer'線,然後檢查跨過這句話後的價值。 –