JQuery appendTo()的不同行为

来源:互联网 发布:windows7如何优化 编辑:程序博客网 时间:2024/05/01 03:40
$('#flower').appendTo('#targets p')$('#car').appendTo('#targets p:first')

1、在此例中,’#targets p’选择的对象超过一个,appendTo()执行时,对’#flower’进行自我复制,如果’#target p’匹配三个,则’#flower’对象自我复制3份,保持自身不变。

2、’#car’在书上的示例中只能找到一个,所以appendTo()仅仅把原对象移动到’#targets p:first’后面,原对象消失。

文章原文:It’s clear from these results that when there are multiple targets, the source element is copied, and when there is only a single target the source element is moved.