Jquery 实时模糊和实时对焦

问题描述 投票:0回答:2

我正在动态打开一个对话框。单击链接时,它会查找信息并将其显示在其中。

$('.comment').live('blur', function(){
    var split = (this.id).split("_");
    var id = split[1];

    $('#face_'+ id).fadeOut();
    $('.commentbutton').hide();
    $("#comments_" + id).slideDown();
})

//////////////////////////////////////////////////

// commentopen 
$(".comment").live("focus", function() { 
    var split = (this.id).split("_");
    var vmid = split[1]; 

    $("#face_" + vmid).fadeIn();
    $("#comments_" + vmid).slideUp();
    $('#commentbutton_' + vmid).show();

});

当您第一次打开对话框时,效果很好,但是如果您关闭它并尝试再次打开它,它就不再起作用,至少在 Firefox 中是这样。

当我发出警报时,它显示 ID 已发送。但为什么

$('.commentbutton')
#face_' + vmid
不再
fadeIn()
slideUp()
slideDown()
和模糊功能不起作用?

我也尝试过 focusin 和 focusout。

谢谢。

jquery focus live blur
2个回答
0
投票

新版本的 jquery live() 已被弃用,您应该使用 on() (注意新格式):

$(document).on('blur','.comment', function(){
   var split = (this.id).split("_");
   var id = split[1]; 
   $('#face_'+ id).fadeOut();
   $('.commentbutton').hide();
   $("#comments_" + id).slideDown();
});
         //////////////////////////////////////////////////

         // commentopen 
$(document).on("focus",".comment", function() { 
   var split = (this.id).split("_");
   var vmid = split[1]; 

   $("#face_" + vmid).fadeIn();
   $("#comments_" + vmid).slideUp();
   $('#commentbutton_' + vmid).show();

});

http://api.jquery.com/on/


0
投票
$(document).on({
    blur: function(){
        var id = this.id.split("_")[0];
        $('#face_'+id).fadeOut();
        $('.commentbutton').hide();
        $("#comments_"+id).slideDown();
    },
    focus: function() {
        var vmid = this.id.split("_")[1];
        $("#face_"+vmid).fadeIn();
        $("#comments_"+vmid).slideUp();
        $('#commentbutton_'+vmid).show();
    }
},'.comment');

用最接近的非动态父文档替换文档。 至于为什么它在第二次点击时不起作用,在没有看到更多实际代码的情况下真的很难回答。

© www.soinside.com 2019 - 2024. All rights reserved.