我有这个:
if($('.content', wrapper).length === 0)
$(data[current].content).appendTo(wrapper);
else
$('.content', wrapper).replaceWith($(data[current].content));
var el = $('.content', wrapper);
这是有效的,但是这段代码应该做同样的事情:
var el = ($('.content', wrapper).length === 0)
? $(data[current].content).appendTo(wrapper)
: $('.content', wrapper).replaceWith($(data[current].content));
搞砸了我的 CSS。
el
在这两种情况下似乎是相同的,但由于某些奇怪的原因,我之后的动画出错了,很可能是因为一些 CSS 更改......
我做错了什么?
最佳答案
.replaceWith 将返回被替换的内容(并且不再在 DOM 中)。来自jQuery docs :
it must be noted that the original jQuery object is returned. This object refers to the element that has been removed from the DOM, not the new element that has replaced it.
关于jQuery DOM 改变了我的 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6481616/