我的代码是这样的。
<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()。 但我不知道.fade如何为动态类工作。
有什么想法吗?
答案 0 :(得分: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>