gpt4 book ai didi

javascript - wrapAll 不换行纯文本

转载 作者:行者123 更新时间:2023-12-02 16:53:28 24 4
gpt4 key购买 nike

有一些 HTML 看起来像这样:

  <body>
Do
all
declarations for
the same
<TT>static</TT> function
or variable
have to include the storage class <TT>static</TT>?
</body>

当我这样做时$('body').children().wrapAll("<div class='container'><div class='row'><div class='col-md-12'></div></div></div>");将所有内容包装成 .container ,它可以工作,只是它不包含纯文本:

  <body>
<div class='container'>
<div class='row'>
<div class='col-md-12'>
<TT>static</TT>
<TT>static</TT>
</div>
</div>
</div>
Do
all
declarations for
the same
function
or variable
have to include the storage class ?
</body>

如何修复此问题以保留原始结构?

最佳答案

children 不返回文本节点。您将需要使用contents

$('body').contents().wrapAll("<div class='container'><div class='row'><div class='col-md-12'></div></div></div>");

$(function(){
$('#children').children().wrapAll("<div class='container'><div class='row'><div class='col-md-12'></div></div></div>");

$('#contents').contents().wrapAll("<div class='container'><div class='row'><div class='col-md-12'></div></div></div>");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<h2>With Children:</h2>
<div id="children">
Do
all
declarations for
the same
<TT>static</TT> function
or variable
have to include the storage class <TT>static</TT>?
</div>

<h2>With Contents:</h2>
<div id="contents">
Do
all
declarations for
the same
<TT>static</TT> function
or variable
have to include the storage class <TT>static</TT>?
</div>

关于javascript - wrapAll 不换行纯文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26390769/

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