Javascript getElementById在克隆对象上失败?
我用的是旋转木马。我定义了一个名为Javascript getElementById在克隆对象上失败?,javascript,jquery,hover,clone,Javascript,Jquery,Hover,Clone,我用的是旋转木马。我定义了一个名为multi-itemcarousel的类。js代码如下: $('.multi-item-carousel .item').each(function(){ var next = $(this).next(); if (!next.length) { next = $(this).siblings(':first'); } next.children(':first-child').clone(true,true).appendTo($(t
multi-itemcarousel
的类。js代码如下:
$('.multi-item-carousel .item').each(function(){
var next = $(this).next();
if (!next.length) {
next = $(this).siblings(':first');
}
next.children(':first-child').clone(true,true).appendTo($(this));
if (next.next().length>0) {
next.next().children(':first-child').clone(true,true).appendTo($(this));
} else {
$(this).siblings(':first').children(':first-child').clone(true,true).appendTo($(this));
}
});
$(".img_change_c").on("mouseenter", function(e) {
// alert("click bound to document listening for #test-element");
var imgH = document.getElementById('img_change').offsetHeight;
alert(imgH);
jQuery(this).find('img').stop().animate({
top: imgH-2*imgH+"px"
}, {
queue: false,
duration: 200
});
});
我选择clone(true,true)
,因为项的子项有事件要侦听。代码如下:
$('.multi-item-carousel .item').each(function(){
var next = $(this).next();
if (!next.length) {
next = $(this).siblings(':first');
}
next.children(':first-child').clone(true,true).appendTo($(this));
if (next.next().length>0) {
next.next().children(':first-child').clone(true,true).appendTo($(this));
} else {
$(this).siblings(':first').children(':first-child').clone(true,true).appendTo($(this));
}
});
$(".img_change_c").on("mouseenter", function(e) {
// alert("click bound to document listening for #test-element");
var imgH = document.getElementById('img_change').offsetHeight;
alert(imgH);
jQuery(this).find('img').stop().animate({
top: imgH-2*imgH+"px"
}, {
queue: false,
duration: 200
});
});
在克隆对象上,会触发事件。但是getElementById('img_change')
是失败的。由于我使用了clone(true,true)
,所以它应该复制每个。那么为什么失败呢?添加html。因为现在不可能帮助你。什么是img_变更id?id在整个文档中应该是唯一的。克隆节点并违反该规则。浏览器无法处理此问题。如何获取单个项目的第二个索引/发生率?它甚至不是长度为1的列表,它只是一个node.add html。因为现在不可能帮助你。什么是img_变更id?id在整个文档中应该是唯一的。克隆节点并违反该规则。浏览器无法处理此问题。如何获取单个项目的第二个索引/发生率?它甚至不是长度为1的列表,它只是一个节点。