Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript can';t追加到jQuery包装_Javascript_Jquery - Fatal编程技术网

Javascript can';t追加到jQuery包装

Javascript can';t追加到jQuery包装,javascript,jquery,Javascript,Jquery,为什么不能附加到用于包装另一个元素的元素上?请参见下面的示例 var$test=$('.test'), $test1=$('.test1'), $move=$('.move'), $testWrapper=$(''), $test1Wrapper=$(''); $test.wrap($testWrapper); //移动项目并返回到包装器 $move.append($test); $testWrapper.append($test);//这条线不行吗? console.log($testWra

为什么不能附加到用于包装另一个元素的元素上?请参见下面的示例

var$test=$('.test'),
$test1=$('.test1'),
$move=$('.move'),
$testWrapper=$(''),
$test1Wrapper=$('');
$test.wrap($testWrapper);
//移动项目并返回到包装器
$move.append($test);
$testWrapper.append($test);//这条线不行吗?
console.log($testWrapper);//还是一个jquery对象?
$test1.after($test1Wrapper);//如果您将元素放置在后面而不是使用它进行包裹,那么它可以工作吗?
$move.append($test1);
$test1Wrapper.append($test1)

测试
测试1
wrap()
似乎克隆了要包装的提供元素的标记,而不是实际元素本身。当您使用
console.log($testWrapper)
并将鼠标悬停在浏览器控制台中的该行上时,您可以在开发人员工具中看到它:通常情况下,DOM元素应该高亮显示,但它不是。因此,变量
$testWrapper
在包装后引用的仍然是(jQuery的集合)一个未附加到DOM的节点

var$test=$('.test'),
$test1=$('.test1'),
$move=$('.move'),
$testWrapper=$('');
$test.wrap($testWrapper);
//移动项目并返回到包装器
$move.append($test);

console.log($testWrapper);//您正在尝试将包装器附加到包装的内容这是一种无限循环…@n00dl3不真正测试是它自己的对象,包装器是它自己的对象,我只包装一次,然后将一个对象移出,然后尝试将其向后移动。。。没有看到移动部分…啊,这是有道理的,我想它需要做一个克隆,就像你有多个对象一样,你不能把一个元素包装成多个。实际上,我只是再次阅读了手册,并更仔细地阅读了它,它实际上说它创建了html结构的副本。我进一步挖掘了一下-如果您首先将包装器元素添加到DOM中,它将按照最初的预期工作。查看更新的代码。哦。。。不,我错了,它创建了另一个副本。:)所以我的回答是:哈哈哈,那会让人困惑的!