2012-01-17 92 views
0

我在Chrome上有这个奇怪的问题 - 我的网页上我使用Mootools注入元素,特别是包含jwplayer视频的lightbox。关于chrome的问题是指的是一个元素,即。 $( 'grid_01');第二次点击它时返回null。为了解决这个问题,我试图测试元素为空,并重新注入它Chrome浏览器 - Mootools注入失败,null元素

  var ss = $('holderdiv'); 
      var x = $('mb_inline_0_-1'); 
      if(x == null) 
      { 
       var el = new Element("div", {id: "mb_inline_0_-1"}); 
      //if this line below runs without error... 
       ss.inject(el); 

      } 
      //.........why would x2 be null? 

      var x2 = $('mb_inline_0_-1'); 

Chrome说它为空。有什么我可以做,以确保DOM更新?

谢谢

回答

1

你的意思是使用抓斗,而不是注入。

ss.grab(el); // Or el.inject(ss); 

您的代码已被ss注入到el中,它永远不会连接到DOM。

1

注入新创建的Element的格式为newElement.inject(existingElement, position);

你的情况

所以,如果你正计划注入新创建的div(在el包含)到$('holderdiv'),应该正是如此做:

var el = new Element('div', { 
    . . . 
}); 
el.inject('holderdiv', 'bottom'); // Although 'bottom' is assumed if nothing is passed 
相关问题