2011-07-07 120 views
0

我正在创建一个脚本,在X分钟后产生内容更衣室。问题是,likeButton内的内容不会显示。模式弹出显示正常,标题和说明也一样。只是不喜欢按钮的内容。如果我将代码块从定时器中取出,它就可以工作。我有点困惑。任何想法发生了什么?缺少元素混淆

var title   = 'Please Press Like'; 
var instructions = 'Like our videos? Join our fanpage. It takes 1 second.'; 
var lockDelay  = 100; // 1200000 = 20 Minutes 

/* STOP EDITING */ 
var boxy; 

$(document).ready(function() { 
    // Create the like button 
    setTimeout(function() { 
     // Create the like button 
     var likeButton = '<div id="likeButton"><fb:like href="" send="false" layout="box_count" width="70" show_faces="false" font=""></fb:like></div>'; 

     // Display the modal 
     boxy = new Boxy('<p id="instructions">' + instructions + '</p>' + likeButton, { 
      title: title, 
      modal: true, 
      closeable: false, 
     }); 
    }, lockDelay); 

    // Close modal after user likes 
    $('#likeButton').mouseover(function() { 
     setTimeout(function() {boxy.hide()}, 3000); 
    }); 
}); 

回答

1

试试这个

var title   = 'Please Press Like'; 
var instructions = 'Like our videos? Join our fanpage. It takes 1 second.'; 
var lockDelay  = 100; // 1200000 = 20 Minutes 

/* STOP EDITING */ 
var boxy; 

$(document).ready(function() { 
    // Create the like button 
    setTimeout(function() { 
     // Create the like button 
     var likeButton = '<div id="likeButton"><fb:like href="" send="false" layout="box_count" width="70" show_faces="false" font=""></fb:like></div>'; 

     // Display the modal 
     boxy = new Boxy('<p id="instructions">' + instructions + '</p>' + likeButton, { 
      title: title, 
      modal: true, 
      closeable: false, 
     }); 

     // Close modal after user likes 
     $('#likeButton').mouseover(function() { 
      setTimeout(function() {boxy.hide()}, 3000); 
     }); 
    }, lockDelay); 

}); 
+0

没错。匿名函数在100ms后创建按钮。脚本实际上是在创建元素之前尝试绑定事件,因此它不起作用,因为元素不存在。 – usoban

+0

我不认为移动鼠标悬停会产生变化,因为mouseover事件隐藏了模式,而不是像likeButton变量中的内容。我试过了,它没有工作。 –

+0

@usoban将其更改为10秒没有任何区别,它仍然无法正常工作。 –