删除 内的一行来自 DOM
当我从
标记中删除一行时,它下面的其余行不会像使用标准
那样向上移动或任何其他元素。
您可以在 http://jsfiddle.net/NN6LC/ 上查看此示例
有人以前遇到过此问题吗或者知道如何解决这个问题?
When I remove a line from a <pre>
tag the rest of the lines below it don't move up like they would if using a standard <div>
or any other element.
You can see an example of this at http://jsfiddle.net/NN6LC/
Has anybody encountered this issue before or knows how to resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在删除跨度,但换行符仍然存在。
从技术上讲,您甚至不允许在
来自 http://lib.ru/WEBMASTER/elements.html#PRE:
解决方法是使用
而不是
编辑:其他人在下面发布了答案,然后删除了他们的答案。我不知道为什么,因为这是一个很好的答案。但这就是他们的做法:
如果您不关心
在技术上不允许,您可以手动删除它和换行符,如下所示: http://jsfiddle.net/doktormolle/KgYyp/
这将在删除之前检查元素后面是否有换行符它,并删除换行符(如果存在)。
You are removing the span, but the newline is still there.
And technically you are not even allowed to have
<span>
s in a<pre>
.From http://lib.ru/WEBMASTER/elements.html#PRE:
The way around it is to use a
<div>
instead of a<pre>
and set styles on the div to make it look like a a<pre>
.EDIT: Someone else had posted the answer below, then deleted their answer. I do not know why, since it was a good answer. But this is how they did it:
If you don't care about
<span>
s not technically being allowed, you can manually remove it and the newline like this: http://jsfiddle.net/doktormolle/KgYyp/This will check for a newline after the element before removing it, and remove the newline too if it exists.
您还必须删除该行后面的换行符。
http://jsfiddle.net/doktormolle/KgYyp/
You must remove the linebreak after the line too.
http://jsfiddle.net/doktormolle/KgYyp/
多么奇怪的行为啊。这是一种解决方法,但我承认它并不完全令人满意。
添加以下 CSS:
请参阅 http://jsfiddle.net/tG8V6/ 了解工作版本。
What curious behaviour. Here's a way around it, but I admit it's not entirely satisfactory.
Add the following CSS:
See http://jsfiddle.net/tG8V6/ for a working version.