gpt4 book ai didi

jquery - 获取 .html 和容器

转载 作者:行者123 更新时间:2023-12-01 03:53:15 26 4
gpt4 key购买 nike

Possible Duplicate:
jQuery - Get selected element's outer HTML

所以我有一个div..

<div id="fred">

里面有东西

<div id="fred">
<tr id="thing1">hello1</tr>
<tr id="thing2">hello2</tr>
</div>

如果我打电话

$("#fred").html();

我只得到里面的元素:

  <tr id="thing1">hello1</tr>
<tr id="thing2">hello2</tr>

我想要整个事情:

<div id="fred">
<tr id="thing1">hello1</tr>
<tr id="thing2">hello2</tr>
</div>

我知道我可以引用使用this[0],但似乎应该有一个更简单的方法..

我试过.andSelf()但显然这并没有达到我的预期效果..

最佳答案

jQuery 不支持 outerHTML:http://api.jquery.com/html/#comment-84945158

(.andSelf 用于元素集,而不是深度。)

我认为最好的解决方案是 el[0].outerHTML (不需要额外的“插件”,原生 JS 总是好的)

关于jquery - 获取 .html 和容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5781278/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com