删除
后加倍中断只留下文字
在我执行以下操作后:
var noTags = document.createElement("DIV");
noTags.innerHTML = html;
noTags.textContent // <- I put this into any textarea
和此文本:
text test <br><br> this text
变成此文本:
text test
this text
我如何获得额外的休息。每次我执行上述 JavaScript 操作时,它们都会继续出现。请帮忙:-(
After I perform following:
var noTags = document.createElement("DIV");
noTags.innerHTML = html;
noTags.textContent // <- I put this into any textarea
and this text:
text test <br><br> this text
Turns into this text:
text test
this text
Some how I get extra break. And they just keep on comming every time I do the above javascript. Please help :-(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您将 html 分配给innerHTML 属性时,浏览器将根据页面设置的DOCTYPE 解释该字符串。您将受到浏览器为该 DOCTYPE 实现的解析器以及浏览器对所述标准的实现的支配;换句话说,“你将保证在不同的浏览器上得到不同的结果”。
也就是说,每个浏览器对以下 HTML 的解释略有不同。
欢迎来到互联网。您的代码会有所不同。
When you assign html to the innerHTML property the browser will interpret that string based on the DOCTYPE set for the page. You will be at the mercy of the parser that the browser implemented for that DOCTYPE and the browser's implementation of said standard; read another way, "you will be guaranteed to get different results on different browsers".
That being said each browser will interpret the following HTML slightly differently.
Welcome to the interwebs. Your code will vary.
那里有两个休息点,为什么你不希望有两条线呢?
中断通常也作为单个闭合标签完成。
而不是
。You have two breaks in there, why wouldn't you expect there to be two lines?
Breaks are usually done as a single closed tag, too.
<br/>
instead of<br>
.