Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript getElementById在克隆对象上失败?_Javascript_Jquery_Hover_Clone - Fatal编程技术网

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的列表,它只是一个节点。