1

我的代码是这样的。

<script>
var i=0;
$(window).load(function() {
  $(function() {
   setInterval(update, 1000);
  });
  function update() {
  i++;
  setTimeout(function(){$("#container").after($('<div>',{text:'Hello',class:'test'+i}))},100);
   $("#container .test"+i).delay(500).fadeTo('slow',0);
  }
});
</script>

.after() 似乎工作。但是 .fadeto() 不起作用。

我知道有用于动态类的实用程序,如 .on() 和 .live() 。但我不知道 .fadeTo 如何为动态类工作。

有任何想法吗?

4

1 回答 1

0

应该是这样的:

<script>
var i=0;
$(window).load(function() {
  $(function() {
   setInterval(update, 1000);
  });
});

  function update() {
    setTimeout(function(){
      // notice the change of class naming convention i.e. .test.t1, .test.t2
      $("#container").after($('<div>',{text:'Hello',class:'test t'+ ++i}))},100);
    }
  }

    // will work with all of the .test class objects within #container
    $("#container .test").on('load',function() {
      $(this).delay(500).fadeTo('slow',0);
    }
</script>
于 2013-06-15T14:27:04.627 回答