我没有得到什么.wrap没有.append。
如果wrap的主要目的是在元素周围添加一些东西,我可以很容易地停止使用.wrap并.append改为使用,对吧?
所以,我使用这个测试代码来附加一些东西:
<script type="text/javascript">
$(document).ready(function(){
var $theWrapper = $('<div class="im-the-wrapper" />');
var $theContent = $('<p>Me</p>');
console.log($theWrapper.get(0));
console.log($theContent.get(0));
$('body').append($theContent);
$theWrapper.append($theContent);
});
</script>
结果:

这个测试代码来包装东西:
<script type="text/javascript">
$(document).ready(function(){
var $theWrapper = $('<div class="im-the-wrapper" />');
var $theContent = $('<p>Me</p>');
console.log($theWrapper.get(0));
console.log($theContent.get(0));
$('body').append($theContent);
$theContent.wrap($theWrapper);
});
</script>
结果:

我以为他们都会返回完全相同的对象,但事实并非如此。后台到底发生了什么?