为什么 IE 对此文本区域的换行方式不同?
有趣的是,这个。我有以下 JS 代码,我将其显示在文本区域中。
var drinks = ['coffee', 'tea', 'Ribena', 'Vimto', 'ginger beer', 'hot chocolate'];
在需要换行的地方,IE 在第一个方括号之前(即数组的开头,但实际的 JS 代码在这里并不重要)断开,而其他浏览器在方括号内断开。
后者似乎是正确的,因为方括号内有空格(即可中断点)。
没有出现时髦的自动换行或空白 CSS。我能做些什么吗?
Interesting one, this. I have the following JS code, which I'm displaying in a textarea.
var drinks = ['coffee', 'tea', 'Ribena', 'Vimto', 'ginger beer', 'hot chocolate'];
Where wrapping is required, IE breaks BEFORE the first square bracket (i.e. the start of the array, but the actual JS code isn't important here), whereas other browsers break WITHIN the square brackets.
The latter seems correct, since there are spaces (i.e. breakable points) within the square brackets.
There is no funky word-wrap or white-space CSS going on. Is there anything I can do about this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几个字符-()[]{}«»%°·/!? Internet Explorer 自动将其解释为换行符。您遇到了一种特殊情况,因为您无法在标记内呈现 HTML,所以您试图在文本区域内进行此操作。
理论上,您可以执行以下操作:
并且 IE 不会自动在诸如 [ 之类的字符处中断,如您的示例所示。除此之外,您显然不能在文本区域内使用 html 标签,因此这是不可能的。
作为替代方案,如果您正在寻找一个,您是否可以尝试在这种情况下使用可滚动的 div 而不是文本区域?
There are several characters -()[]{}«»%°·/!? that Internet Explorer automatically interprets as a line break. You have kind of a special situation in that you are trying to make this work inside of a textarea since you can't render HTML within the tag.
In theory, you could do something like:
and IE would not automatically break at characters such as the [ as noted by your example. Except, you obviously can't use the html tag inside of a textarea so this just isn't possible.
As an alternative, if you are seeking one, might you try using a scrollable div instead of a text area for this situation?