有一些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>我如何修复这个问题,使其保留原来的结构?
发布于 2014-10-16 03:46:35
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>
https://stackoverflow.com/questions/26390769
复制相似问题