2014-09-24 29 views
0

我又需要你的幫助,並非所有  s的被替換轉換從一個表格單元格文本到文本區域

這似乎並不是所有的; NBSP的被捕獲並轉換成合適的文本空間。爲什麼替換函數會捕獲一些;而不捕獲並轉換其他函數。

我附上了問題的照片。 enter image description here

這裏有一個快速小提琴:http://jsfiddle.net/n6vwrt2v/

在這一個我超越困惑。

問題代碼:

var y = document.getElementById("table1").children[0].children[0].innerHTML 

//some processing first to replace the <br>'s before the final output 

y = y.replace(/\s*<br\s*\/?>\s*/g, '\n') 

y = y.replace('&nbsp;',' ') 
+0

'Y = y.replace(/   /,」「)' – 2014-09-24 17:17:02

回答

1

嘗試通過串循環和更換,直到沒有剩下。替換隻會替換字符串中的第一個。例如:

while(y.indexOf("&nbsp;") != -1) 
{ 
    y.replace("&nbsp;", " "); 
} 
+0

我嘗試過,但你的循環只是凍結起來,沒有任何反應。 – user1451890 2014-09-24 18:03:30

相關問題