问题描述
嗨
我有一点点问题。
我将输入字段中的数据传输到div,这样你就可以看到profil
将在您输入数据时显示。
我只是将它放在我的输入字段中:
onkeyup =" document.getElementById (''javao'')。innerHTM L = this.value;"
这个:< span id =" javao">< / spansome在页面上的其他位置。 />
这很好用,我也用textarea做同样的事情。
但是......文本字段中的断点不会转移到div。
我在网上搜索但似乎无法找到任何相关信息。我还用
尝试了使用nl2br的不同解决方案等等,但我无法得到
工作。
所以问题是,如何从textarea传输回车键?
Hi
I have a little probelm.
I tranfer som data from input fields to a div so you can see how a profil
will look as you type in your data.
I just put this in my input field:
onkeyup="document.getElementById(''javao'').innerHTM L=this.value;"
And this : <span id="javao"></spansomewhere else on the page.
This works fine and I also do the same thing with a textarea.
But... The breaks made in the textfield is not tranfered to the div.
I have search the net but can''t seem to find anything about it. I have also
tried different solutions using nl2br and so on, but I just can''t get it to
work.
So the quetion is, how do I transfer the the enter key from a textarea ?
推荐答案
你需要用tex />
< br替换textarea中的所有< cr>< lf [text end-of-line] / [HTML end-of-line]
You need to replace all <cr><lf[text end-of-line] in textarea with
<br/[HTML end-of-line]
你需要用tex />
< br替换textarea中的所有< cr>< lf [text end-of-line] / [HTML end-of-line]
ok ...所以换行符实际上是< cr>< lfin a textarea?
但是如何在javascript中运行时替换它?
You need to replace all <cr><lf[text end-of-line] in textarea with
<br/[HTML end-of-line]
ok... so the line breaks is actually <cr><lfin a textarea ?
But how do I replace this on the run in javascript ?
这类东西 -
函数clean(asd){
asd = asd.replace(/ \r / g,"")//在IE和Opera中使用'supress''返回''
asd = asd。替换(/ \ n / g,唱歌)//新行 - 空格或< br}
(是的,可以内联为
newstring = oldstring.replace(/ \ r / g,"")。replace(/ \ n / g,sing)
where sing ="< br> ;或< p>"(记得添加< / palso)
您可能需要担心标签(\t)和额外空格以及多个
''输入'
Something of this sort --
function clean(asd) {
asd=asd.replace(/\r/g,"") //supress ''returns'' used in IE and Opera
asd=asd.replace(/\n/g,sing) //new line --space or <br }
(yes, can be inline as
newstring=oldstring.replace(/\r/g,"").replace(/\n/g,sing)
where sing = "<br>" or "<p>" (remember to add the </palso)
You might want to worry about tabs (\t) and extra spaces and multiple
''enter''s
这篇关于如何从textarea转移休息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!