sophiehui

导航

 

clone()方法用于复制一个元素,但是被复制出来的元素不具备复制的功能,如果希望被复制出来的元素也具备复制的功能,需要给clone()方法加上true这个参数,即clone(true).

例如:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta charset="UTF-8">
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<style type="text/css">
img {
border: solid 1px #ccc;
padding: 3px;
margin: 5px
}
</style>
<script type="text/javascript">
$(function() {
$("img").click(function() {
$(this).clone(true).appendTo("span");
})
})
</script>
</head>

<body> <span><img title="封面" alt="1" src="Images/img04.jpg" /></span> </body>

</html>

posted on 2016-08-16 18:51  sophiehui  阅读(475)  评论(0编辑  收藏  举报