首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wrapAll不换行纯文本

wrapAll不换行纯文本
EN

Stack Overflow用户
提问于 2014-10-16 03:43:14
回答 1查看 66关注 0票数 0

有一些HTML看起来像这样:

代码语言:javascript
复制
  <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中时,它可以正常工作,但它不包含纯文本:

代码语言:javascript
复制
  <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>

我如何修复这个问题,使其保留原来的结构?

EN

回答 1

Stack Overflow用户

发布于 2014-10-16 03:46:35

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

代码语言:javascript
复制
$('body').contents().wrapAll("<div class='container'><div class='row'><div class='col-md-12'></div></div></div>");

代码语言:javascript
复制
$(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>");
});
代码语言:javascript
复制
<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>

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26390769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档