gpt4 book ai didi

jquery - 使用 jQuery 动态添加按钮

转载 作者:太空宇宙 更新时间:2023-11-03 19:43:15 24 4
gpt4 key购买 nike

我正在尝试动态添加一个按钮 - 第一个按钮有效,但其他按钮无效。我以前使用的是 live 函数,但 jQuery 1.9.1 删除了该函数。我应该怎么做才能使新添加的按钮起作用?

HTML 代码:

<div class="take">
<p>this is the para</p>
<button class="test">copy</button>
</div>

jQuery 代码:

$('.test').on('click', function() {
var a = $(this).parent();
new.clone().insertAfter(a);
})

这是 jsfiddle .

最佳答案

在 clone 中传递 true 将解决您的问题 - jsfiddle

$('.test').on('click', function() {
var o = $(this).parent();
o.clone(true).insertAfter(o);
})

注意:new 是 JavaScript 中的关键字,因此不要将其用作变量。

关于jquery - 使用 jQuery 动态添加按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15905294/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com