admin管理员组文章数量:1398206
In all versions of IE (I'm testing IE11 at the moment) new line breaks inside of textarea
elements aren't working...
function id_(id)
{
var r = false;
if (document.getElementById(id))
{
r = document.getElementById(id);
}
return r;
}
window.onload = function()
{
for (i in document.getElementsByTagName('audio')[0])
{
id_('test').value = id_('test').value + '\n' +i;
}
}
How can I force IE to break lines in a textarea
element? No frameworks.
I've tried \n\r
, \r\n
, \r
and \n
.
In all versions of IE (I'm testing IE11 at the moment) new line breaks inside of textarea
elements aren't working...
function id_(id)
{
var r = false;
if (document.getElementById(id))
{
r = document.getElementById(id);
}
return r;
}
window.onload = function()
{
for (i in document.getElementsByTagName('audio')[0])
{
id_('test').value = id_('test').value + '\n' +i;
}
}
How can I force IE to break lines in a textarea
element? No frameworks.
I've tried \n\r
, \r\n
, \r
and \n
.
- 2 jsfiddle/ff5kqtru this seems to work in IE11. What are u trying to achieve by that loop? – Comfortably Numb Commented Sep 22, 2014 at 17:21
-
Try this
$('#test').val($('#test').value + '\n' +i);
ref:stackoverflow./questions/5583040/… – Sainath Motlakunta Commented Sep 22, 2014 at 17:24 -
for (i in document.getElementsByTagName('audio')[0])
seems weird, are you sure it isn'tfor (i in document.getElementsByTagName('audio'))
? – Igor Jerosimić Commented Sep 22, 2014 at 17:28 -
1
@IgorJerosimić, I assume he's iterating through the properties of the first
audio
tag, hence the[0]
. – Rick Hitchcock Commented Sep 22, 2014 at 17:39
3 Answers
Reset to default 5After minimizing the code the issue was the CSS white-space
property which I fixed with the code below.
* {white-space: nowrap;}
textarea {white-space: pre;}
In IE, \n
does indeed generate line breaks in textarea
elements. That is, this code:
<textarea id="target">default text here</textarea>
<script>document.getElementById('target').value = 'a\nb';</script>
does, in IE, result in a textarea which holds the value default text here
for an unimaginably short time followed by the value:
a
b
If you really want to test your browser, I have put this on a JSFiddle at: http://jsfiddle/91mj2arh/
This Fiddle based on your code adds line feeds in my version of IE11, and it seems to acplish what you're looking for to iterate the audio
element's properties:
http://jsfiddle/ff5kqtru/5/
If you post your HTML, we may be able to spot a problem.
本文标签: javascriptInternet Explorer n line breaks not workingStack Overflow
版权声明:本文标题:javascript - Internet Explorer n line breaks not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744141219a2592631.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论