javascript - Internet Explorer n line breaks not working - Stack Overflow

In all versions of IE (I'm testing IE11 at the moment) new line breaks inside of textarea elements

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.

Share Improve this question edited Sep 22, 2014 at 17:27 John asked Sep 22, 2014 at 17:17 JohnJohn 13.8k15 gold badges111 silver badges191 bronze badges 4
  • 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't for (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
Add a ment  | 

3 Answers 3

Reset to default 5

After 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744141219a4560217.html

相关推荐

  • javascript - Internet Explorer n line breaks not working - Stack Overflow

    In all versions of IE (I'm testing IE11 at the moment) new line breaks inside of textarea elements

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信