gpt4 book ai didi

jquery - 使用悬停事件克隆元素?

转载 作者:行者123 更新时间:2023-12-01 03:20:06 25 4
gpt4 key购买 nike

HTML:

<div id='task-header'>
</div>
<div id='tasks'>
<a href="#" id ="add">Add</a>
<ul>
<li class ="editable">
<form class='task'>
<input class='textfield' type='text' />
</form>
<a href="#" class="delete">Delete this row</a>
</li>
</ul>
</div>
<div id='task-footer'></div>

jQuery:

var item = $("#tasks ul li:eq(0)").clone(true); // need to clone for new add
$('#add').click(function() {
var taskItem = item.clone(true);
$('#tasks ul').append(taskItem);
taskItem.find(':input:text').val("");
return false;
});

$('body').on('click', '.delete', function() {
$(this).parent('li').remove();
return false;
});

$(".editable").hover(function() {
$(this).addClass("editHover");
}, function() {
$(this).removeClass("editHover");
});​

JSFiddle: http://jsfiddle.net/t67yJ/

我设置了我的clone(true)参数,但我仍然无法获取我的克隆 <li>具有悬停效果。我该怎么办?

谢谢。

最佳答案

只需将克隆调用移至处理程序下方,如下所示,

$(".editable").hover(function() {
$(this).addClass("editHover");
}, function() {
$(this).removeClass("editHover");
});

var item = $("#tasks ul li:eq(0)").clone(true); // need to clone for new add

DEMO

关于jquery - 使用悬停事件克隆元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10855750/

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