admin管理员组文章数量:1180476
document.getElementById('area').onkeyup=keydown;
function keydown (event) {
if (event.target.id=='area' && event.which==13) {
document.getElementById('arsh').innerHTML+="\n";
}
}
Arsh is the ID of my paragraph where i want to add the new line why is this not working can anyone help me ?I just want to add a new line when Enter is pressed in the textarea (ID area) to my Paragraph (ID arsh).
here is the HTML
<textarea ID="area" class="in">
Message
</textarea>
<br />
<br />
<p ID="tiesh" class="sh">
</p>
<br />
<br />
<p ID="arsh" class="sh">
</p>
<br />
</div>
I am basically trying to do it like here in stackoverflow when you press enter in the textarea down the paragraph jumps down a line also.
document.getElementById('area').onkeyup=keydown;
function keydown (event) {
if (event.target.id=='area' && event.which==13) {
document.getElementById('arsh').innerHTML+="\n";
}
}
Arsh is the ID of my paragraph where i want to add the new line why is this not working can anyone help me ?I just want to add a new line when Enter is pressed in the textarea (ID area) to my Paragraph (ID arsh).
here is the HTML
<textarea ID="area" class="in">
Message
</textarea>
<br />
<br />
<p ID="tiesh" class="sh">
</p>
<br />
<br />
<p ID="arsh" class="sh">
</p>
<br />
</div>
I am basically trying to do it like here in stackoverflow when you press enter in the textarea down the paragraph jumps down a line also.
Share Improve this question edited Jan 5, 2013 at 22:16 Csak Zoli asked Jan 5, 2013 at 21:59 Csak ZoliCsak Zoli 4281 gold badge4 silver badges11 bronze badges 7- 1 isn't enter key already creating a new line in a textarea? – keune Commented Jan 5, 2013 at 22:01
- in the textarea yes but i want it to create in the paragraph called arsh ID – Csak Zoli Commented Jan 5, 2013 at 22:02
- What does your HTML look like? Can you make a Fiddle? – HellaMad Commented Jan 5, 2013 at 22:02
- This is a very small part of the code but its not working here – Csak Zoli Commented Jan 5, 2013 at 22:03
- @CsakZoli It's working for me. Inspect the paragraph and you will see the newlines. jsfiddle.net/afgtB – HellaMad Commented Jan 5, 2013 at 22:06
4 Answers
Reset to default 30Using CSS, give #arsh
(or any other elements that you want to render new lines) this attribute.
white-space: pre-wrap;
document.getElementById('arsh').innerHTML=document.getElementById("area").value.replace(/\n/g,'<br />')
this will do the job
The newline character (\n) do not render as new lines on the screen. You probably need to add an HTML break instead:
document.getElementById('arsh').innerHTML+="<br />";
<p style="white-space: pre-wrap;"><?php echo $row['description_text'];?></p>
本文标签: javascriptNew line in paragraph when Enter is pressed in textareaStack Overflow
版权声明:本文标题:javascript - New line in paragraph when Enter is pressed in textarea - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738136545a2065484.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论