奇怪jQuery的错误,尝试使用保鲜膜后追加()()时 [英] Wierd jquery bug, when trying to append() after using wrap()

查看:104
本文介绍了奇怪jQuery的错误,尝试使用保鲜膜后追加()()时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jQuery:

1)创建一个容器

2),用它包裹的元素

3)通过传递对象jQuery选择和尝试的元素添加到容器选择容器

为什么不元素附加?

在这里看看这个例子: http://jsfiddle.net/Tngh4/

  VAR容器=使用document.createElement(分区);
//包装纸和容器一些随机因素
$(#randomElem)包裹(容器)。VAR ELEM =使用document.createElement(分区);
//选择元素这种方式,并使用附加在一个陌生的错误结果
$(集装箱).append(ELEM);


解决方案

.wrap与副本包装的元素传递的元素,而不是在元素本身通过。


  

这种结构的副本将围绕每个匹配元素的元素包裹。此方法返回原来设置为链接的目的元素。


http://api.jquery.com/wrap

这是你的小提琴使用 .wrap 替代http://jsfiddle.net/Tngh4/1/

Using jquery:

1) Create a container

2) Wrap an element with it

3) Select container by passing an object to jquery selector and try to add an element to the container

Why doesn't element append?

Look at this example here: http://jsfiddle.net/Tngh4/

var container = document.createElement("div");
//Wrapping some random element with the container
$("#randomElem").wrap(container);

var elem = document.createElement("div");
//Selecting element this way and using append results in a strange bug
$(container).append(elem);

解决方案

.wrap wraps the element with a copy of the passed in element, not the passed in element itself.

A copy of this structure will be wrapped around each of the elements in the set of matched elements. This method returns the original set of elements for chaining purposes.

http://api.jquery.com/wrap

Here's your fiddle to use an alternative to .wrap http://jsfiddle.net/Tngh4/1/

这篇关于奇怪jQuery的错误,尝试使用保鲜膜后追加()()时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆