jQuery:删除结束标记 [英] jQuery: Remove a closing tag

查看:108
本文介绍了jQuery:删除结束标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用jQuery删除一个结束的HTML-Tag?

Is there a way to use jQuery to remove a single closing HTML-Tag?

示例:

  <div class="one">
    <div class="two">CONTENT</div>
  </div>
</div>

我必须删除最后一个,这意味着div.one关闭后的结束div-tag。

I have to remove the last , that means the closing div-tag after div.one is closed.

不幸的是我必须用JS / jQuery做这个,因为我在这个项目上使用的系统无法删除它。

Unfortunately I have to do this with JS/jQuery since the System I'm working with on this project can't remove it.

推荐答案

不,这是不可能的。在页面中根本没有关闭标签。

No, that is not possible. There simply are not closing tags at all in the page.

结束标签在解析之前存在于HTML代码中,一旦解析完每个元素是一个对象,而不是标记中的起点和终点。

The closing tags exists in the HTML code before it's parsed, once it's parsed each element is one object, not a start and end point in the markup.

浏览器会尝试修复无效标记,但问题是不同的浏览器会做不同的事情。某些浏览器可能会忽略额外的结束标记,而其他浏览器可能会暗示开始标记使其成为完整元素。您可以尝试重新排列元素,使它们恢复到没有额外结束标记的状态,但要做到这一点,您需要知道在解析代码时所有不同的浏览器将会做什么。

The browser will have tried to fix the invalid markup, but the problem is that different browsers will have done different things. Some browsers may ignore the extra closing tag, while others may imply a starting tag to make it a complete element. You could try to rearrange the elements to have them restored to the state they would have been without the extra closing tag, but to do that you need to know what all different browsers will have done when parsing the code.

更糟糕的是,如果该代码在另一个 div 中,那么那个标签就会在那里结束,并且无效代码会在那之后出现。如何处理取决于代码在您所显示的代码之外的内容,以及不同的浏览器可能以不同的方式处理无效代码。

Even worse, if that code is inside another div, it would be that tag that ended there, and the invalid code would come after that. How that would be handled depends on what the code is outside the code that you have shown, and also there different browsers may handle the invalid code in different ways.

这篇关于jQuery:删除结束标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆