jQuery:在每个()中使用live()

Kar*_*rem 8 jquery

我在这里有这个功能:

$("a.fancybox_vid").each(function(){
   $(this).fancybox({
    titleShow     : false,
    width:    640,
    height:   395,
    autoDimensions: false,
    overlayOpacity: 0.6,
    href: "misc/mc.php?v="+$(this).attr('id')
  }); 
});
Run Code Online (Sandbox Code Playgroud)

现在添加了一个带有c lass .fancybox_vid的链接,然后这将无效.只有从一开始就存在.我怎么能在每个()中都有live().

use*_*716 4

如果您想要方法的“类似实时”功能,您可以使用livequery插件

$(function() {
    $('a.fancybox').livequery(function() {
        $(this).fancybox({
            titleShow     : false,
            width:    640,
            height:   395,
            autoDimensions: false,
            overlayOpacity: 0.6,
            href: "misc/mc.php?v="+$(this).attr('id')
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

fancybox...尽管在新创建的元素上调用插件会更好(开销更少) 。