29. 使用clone()方法复制元素节点

版权声明:本文为大都督作者的原创文章,未经 大都督 允许也可以转载,但请注明出处,谢谢! 共勉! https://blog.csdn.net/qq_37335220/article/details/85084755

1. 效果图

在这里插入图片描述

2. html代码

<!DOCTYPE html>
<html>
<head>
    <title>使用clone()方法复制元素节点.html</title>
         <style type="text/css">
           img{border: solid 1px #ccc;padding: 3px;margin: 5px;}
    	</style>
</head>
<body>
	<span>
		<img alt="小猪" src="../img/pig.jpg" style="width: 70px;height: 70px;">
	</span>
<script src="../jquery.min.js"></script>
<script type="text/javascript">
	$(function(){
		$("img").click(function(){
			$(this).clone(true).appendTo("span");
		})
	});
</script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_37335220/article/details/85084755