我的问题与我正在运行确认的页面动态应用的元素有关。代码正确地定位元素并询问确认部分,但问题是如果我选择是,我不知道隐藏返回值的位置,它不像我下面的想法那样在类中设置,也不返回值各种。
任何人都知道如何从我要删除的元素的确认中获得某种形式的返回值?
$('.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:' - '}
});
}
答案 0 :(得分: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();