我的问题是我的变量flag
没有以某种方式更新,我什至试图用setTimeout
函数来做到这一点,但是没有运气!
的JavaScript
function confirmed(msg, okFtn, cnclFtn){
flag=false;
$(document.createElement('div')).html('\
<div style="max-width:250px;width:100%;">'+msg+'\
<p>\
<button value="yes" class="button small gradient blue left rnd5 cnfrm">OK</button>\
<button value="no" class="button small gradient blue left rnd5 cnfrm">Cancel</button>\
</p></div>')
.modal({
onShow: function (dialog) {
$('.simplemodal-close').remove();
$("#simplemodal-container").css({'height': 'auto','width':'auto'});
$(window).trigger('resize.simplemodal');
},
onClose: function(){
console.log(flag);
if(flag)
return true;
else
return false;
}
});
$('button.cnfrm').click(function(){
flag=true;
if ($(this).val() == 'yes') {
if(okFtn && typeof okFtn === 'function')
okFtn();
} else {
if(cnclFtn && typeof cnclFtn === 'function')
cnclFtn();
}
setTimeout(function(){$.modal.close();}, 1000);
});
}
这是我所说的Fiddle链接。
由于未设置变量,因此$.modal.close()
无法正常工作,我想要的是仅当单击按钮OK
或时,才关闭模式对话框cancel
。
http://www.ericmmartin.com/projects/simplemodal/
从文档中:
onClose:用于为模态对话框元素的关闭添加效果。应用效果等后,需要调用$ .modal.close() ; 因此SimpleModal可以正确地重新插入数据并清理对话框元素。
您需要$.modal.close()
在onClose()
处理程序中包含对的调用,例如
onClose: function(){
console.log(flag);
if(flag) $.modal.close();
}
ps。至于flag
变量,它的设置完全符合您的预期。这不是问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句