使用這個去除我的newLine字符Javascript - document.createTextNode()
是否有替代這將呈現html?
function viewCommentToggle(comment)
{
theRow = document.getElementById("id"+comment.id);
idx = 2;
// Comment field
cell = theRow.cells[idx];
while(cell.childNodes.length > 0) cell.removeChild(cell.childNodes[0]);
element = document.createTextNode(comment.comment);
cell.appendChild(element);
}
這是林concered有:
element = document.createTextNode(comment.comment);
只是一個供參考....這是我做過什麼和它的工作:
function viewCommentToggle(comment)
{
theRow = document.getElementById("id"+comment.id);
idx = 2;
// Comment field
//cell = theRow.cells[idx];
// while(cell.childNodes.length > 0) cell.removeChild(cell.childNodes[0]);
cell = $("#id"+comment.id+" > td:eq("+idx+")");
$(cell).empty();
$(cell).html(comment.comment == null ? "" : comment.comment.replace(/\n/g,"<br/>").replace(/\r/g,""));
yup,使用jQuery確實讓這一切變得更容易... – Alnitak 2012-04-18 20:52:37