2011-06-07 87 views
0

我的问题是关于动态应用的元素到我正在运行确认的页面。代码正确地定位元素并询问确认部分,但问题是如果选择“是”,我不知道隐藏了返回值的位置,它不是像下面的我的想法那样在类中设置,也不返回值各种各样的。JQUERY LIVE确认问题

任何人都知道如何从确认我想删除的元素获得某种形式的返回值?

$('.deleteMe').live('click', function() { 

     confirmFunction(this); 
     if ($(this).hasClass('confirm')){ alert("yea");} else {alert("no");} 
    }); 

    function confirmFunction(element) { 
     $(element).confirm({ 
      msg:'Confirm Action!<br />', 
      stopAfter:'ok', 
      eventType:'click', 
      timeout:5000, 
      buttons: { ok:'Yes', cancel:'No', separator:' - '} 
     }); 
    } 

回答

1

从我的插件页面上的例子理解,它应该是这样的:

指定应该运行,如果确认成功,则分配确认插件单击处理程序。

$('.deleteMe').live('click',function() { 
    // Code here for when they click YES on the confirm box. 
    // This only executes in 2 scenarios, either the item was clicked 
    // and the confirm plugin was not active, or it was active and 
    // the user selected Yes. 
}); 

function updateConfirms() { 
    $('.deleteMe').confirm({ 
     msg:'Confirm Action!<br />', 
     stopAfter:'ok', 
     eventType:'click', 
     timeout:5000, 
     buttons: { ok:'Yes', cancel:'No', separator:' - '} 
    }); 
} 

updateConfirms(); 

由于您提到的动态性质,您需要在添加需要确认的新元素后调用updateConfirms()。

编辑:让我们尽量不使用Live,并刷新任何添加后单击处理和确认:

function updateConfirms() { 
    $('.deleteMe').click(function() { 
    // Code here for when they click YES on the confirm box. 
    // This only executes in 2 scenarios, either the item was clicked 
    // and the confirm plugin was not active, or it was active and 
    // the user selected Yes. 
    }); 

    $('.deleteMe').confirm({ 
    msg:'Confirm Action!<br />', 
    stopAfter:'ok', 
    eventType:'click', 
    timeout:5000, 
    buttons: { ok:'Yes', cancel:'No', separator:' - '} 
    }); 
} 

updateConfirms(); 
+0

嗨,我已经尝试似乎已不幸的是说什么也不会删除方法链接。我添加了被调用的元素,然后按照您的指示运行该函数,但似乎并未将确认处理程序添加到.deleteMe元素。只要我点击deleteMe元素,它就直接进入警报hello call而不是确认。 – John 2011-06-07 20:26:53

+0

@John好吧,也许这是导致问题的'生活'部分。我会发布一个快速修改。 – Fosco 2011-06-07 20:29:49

+0

好男人欣赏:) – John 2011-06-07 20:30:33