我正在动态打开一个对话框。当点击一个链接时,它会查找信息并在其中显示。
$('.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。
谢谢。
发布于 2012-04-24 00:54:16
在新版本的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/
发布于 2012-04-24 00:59:27
$(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');将文档替换为最接近的非动态父级。至于为什么它在第二次点击时不起作用,如果没有看到更多的实际代码,就很难回答这个问题。
https://stackoverflow.com/questions/10284772
复制相似问题