如何在 JavaScript 中编写 <br/> 标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4803967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I write a <br/> tag in JavaScript?
提问by Vinay Gayakwad
How do I write a <br/>
tag in JavaScript?
如何<br/>
在 JavaScript 中编写标签?
回答by Quentin
var mybr = document.createElement('br');
someElement.appendChild(mybr);
Further reading:
进一步阅读:
回答by Jake Aitchison
document.write('<br/>');
this should do the trick.
这应该可以解决问题。
回答by David
document.write('<br />');
Or, since no Stack Overflow question on JavaScript would be complete without jQuery...
或者,因为没有 jQuery,关于 JavaScript 的堆栈溢出问题将是不完整的......
http://www.thenerdary.net/post/20965430596/beautiful-element-creation-with-jquery
http://www.thenerdary.net/post/20965430596/beautiful-element-creation-with-jquery
回答by visit
Use the operator + in the document.write(var1 + "text" + and the break tag);
在 document.write(var1 + "text" + 和 break 标签中使用运算符 +);