如何在javascript中创建硬回车或新行

时间:2012-01-24 17:38:06

标签: javascript

我有以下代码段:

document.getElementById('PS_FORM/SUBJECT_PROPERTY/Business_Comments').value = com_textcl + "\n" ;

document.getElementById('PS_FORM/SUBJECT_PROPERTY/Business_Comments').value = com_text;  

我希望每个值都在他们自己的行中。有没有办法完成这个?

由于

1 个答案:

答案 0 :(得分:3)

假设元素(PS_FORM/SUBJECT_PROPERTY/Business_Comments)是textarea,那么JS应该是:

document.getElementById('PS_FORM/SUBJECT_PROPERTY/Business_Comments').value= 
    com_textcl + "\n" + com_text;

如果它是SELECT,则代码会有所不同(更新您的问题)。

如果它是div或其他HTML元素(而不是FORM元素),则代码更像是:

document.getElementById('PS_FORM/SUBJECT_PROPERTY/Business_Comments').innerHTML= 
    com_textcl + "<br />\n" + com_text;