jquery操作元素具备唯一性
jquery 元素
jquery选择页面中的元素,这些元素是真的被“选择出来”了,如果你把这些元素用于其它地方,原来的元素将会消失!
这是我在做潮汕风情网时发现的。我的设想是通过jquery把文章内容中的某些链接提取出来,统一放到文章内容的下面,而文章内容要保持不变。起初的代码是这样写的:
代码如下
-
$("#peopleLinkExtend").append("<ul></ul>");
-
$(".people_link").each(function(){
-
$("#peopleLinkExtend ul").append("<li></li>");
-
$("#peopleLinkExtend ul li:last").append(this);
-
$("#peopleLinkExtend ul li:last").append("的相关资料");
-
});
结果原来文章中的链接消失了。后来想起jQuery有克隆元素的功能,于是改成这样:
代码如下
-
$("#peopleLinkExtend").append("<ul></ul>");
-
$(".people_link").clone().each(function(){
-
$("#peopleLinkExtend ul").append("<li></li>");
-
$("#peopleLinkExtend ul li:last").append(this);
-
$("#peopleLinkExtend ul li:last").append("的相关资料");
-
});
结果就正常了。参考实例页面:http://www.csfqw.com/html/6/2008112511522663.html