我有一个组合的JavaScript和我的jsp,它添加了一些文本并转义它。我还有一些javascrpt,它允许我在提交文本后对其进行编辑。然而,当点击编辑按钮时,html呈现。如何使用javascript在“innerHtml”属性中转义html?
function editCommentToggle(id)
{
theRow = document.getElementById("id"+id);
//user = theRow.cells[0].innerHTML;
//date = theRow.cells[1].innerHTML;
--> com = theRow.cells[2].innerHTML;
idx = 2;
maxlength = 250;
// Comment field
cell = theRow.cells[idx];
while(cell.childNodes.length > 0) cell.removeChild(cell.childNodes[0]);
element = document.createElement("textarea");
element.id="comments-"+id;
element.rows="3";
element.value = com;
element.style.width = "400px";
element.maxLength = "250";
element.onfocus = element.onkeydown = element.onkeyup = function(){return characterCounterEdit(undefined, maxlength, this);};
cell.appendChild(element);
“theRow.cells [2] .innerHTML;”正在抓取该单元格中的文本或html,但如果说有'换行',它会显示一个<br>
.....我应该如何构造这个以保留转义的html?
感谢名单
thanx朋友...让我试试 –
工作........... –