Jquery教程
Jquery动效
Jquery HTML/CSS
Jquery 事件
jquery常用

jQuery clone()

jQuery clone()方法用于复制匹配元素集。它还会复制其子节点,文本和属性。 clone()方法是在页面上复制元素的便捷方法。
语法:
$(selector).clone(true|false)

jQuery clone()方法的参数

参数 说明
true 它指定还应复制事件处理程序。
false 这是默认参数。它指定不应复制事件处理程序。

jQuery clone()方法的示例

让我们以一个示例来演示jQuery clone()方法的效果。
<!DOCTYPE html>
<html>
<head>
<script src="/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").clone().appendTo("body");
    });
});
</script>
</head>
<body>
<p><b> lidihuo.com is a popular tutorial website.</b></p>
<p><b>lidihuo.com is a training institute also.</b></p>
<button>Click here, to clone all p elements, and append them to the body element</button>
</body>
</html>
输出:

lidihuo.com is a popular tutorial website.

lidihuo.com is a training institute also.

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4