admin管理员组文章数量:1402560
im using the following code as replacements for confirm boxes in javascript.
function fancyAlert(msg) {
jQuery.fancybox({
'modal' : true,
'content' : "<div style=\"margin:1px;width:240px;\">"+msg+"<div style=\"text-align:right;margin-top:10px;\"><input style=\"margin:3px;padding:0px;\" type=\"button\" onclick=\"jQuery.fancybox.close();\" value=\"Ok\"></div></div>" }); }
function fancyConfirm(msg, callback) {
var ret;
jQuery.fancybox({
'modal' : true,
'content' : "<div style=\"margin:1px;width:240px;\">"+msg+"<div style=\"text-align:right;margin-top:10px;\"><input id=\"fancyConfirm_cancel\" style=\"margin:3px;padding:0px;\" type=\"button\" value=\"Cancel\"><input id=\"fancyConfirm_ok\" style=\"margin:3px;padding:0px;\" type=\"button\" value=\"Ok\"></div></div>",
onComplete : function() {
jQuery("#fancyConfirm_cancel").click(function() {
ret = false;
jQuery.fancybox.close();
})
jQuery("#fancyConfirm_ok").click(function() {
ret = true;
jQuery.fancybox.close();
})
},
onClosed : function() {
if (typeof callback == 'function'){ callback.call(this, ret); };
}
});
}
function fancyConfirm_text() {
fancyConfirm("Ceci est un test", function(ret) {
alert(ret)
})
}
and im using a hyperlink like this:
<a href="/" onclick="fancyConfirm("Are you sure you want to delete?");">Test</a>
im stuck, it just wont display anything?, i think its got something to do with the callback variable required for fancyConfirm but im unsure what that means and how it applies.
thanks for your help.
im using the following code as replacements for confirm boxes in javascript.
function fancyAlert(msg) {
jQuery.fancybox({
'modal' : true,
'content' : "<div style=\"margin:1px;width:240px;\">"+msg+"<div style=\"text-align:right;margin-top:10px;\"><input style=\"margin:3px;padding:0px;\" type=\"button\" onclick=\"jQuery.fancybox.close();\" value=\"Ok\"></div></div>" }); }
function fancyConfirm(msg, callback) {
var ret;
jQuery.fancybox({
'modal' : true,
'content' : "<div style=\"margin:1px;width:240px;\">"+msg+"<div style=\"text-align:right;margin-top:10px;\"><input id=\"fancyConfirm_cancel\" style=\"margin:3px;padding:0px;\" type=\"button\" value=\"Cancel\"><input id=\"fancyConfirm_ok\" style=\"margin:3px;padding:0px;\" type=\"button\" value=\"Ok\"></div></div>",
onComplete : function() {
jQuery("#fancyConfirm_cancel").click(function() {
ret = false;
jQuery.fancybox.close();
})
jQuery("#fancyConfirm_ok").click(function() {
ret = true;
jQuery.fancybox.close();
})
},
onClosed : function() {
if (typeof callback == 'function'){ callback.call(this, ret); };
}
});
}
function fancyConfirm_text() {
fancyConfirm("Ceci est un test", function(ret) {
alert(ret)
})
}
and im using a hyperlink like this:
<a href="http://www.example./" onclick="fancyConfirm("Are you sure you want to delete?");">Test</a>
im stuck, it just wont display anything?, i think its got something to do with the callback variable required for fancyConfirm but im unsure what that means and how it applies.
thanks for your help.
Share Improve this question edited Jul 15, 2016 at 12:25 unloco 7,3604 gold badges51 silver badges61 bronze badges asked Apr 12, 2011 at 22:14 PHPNewEEPHPNewEE 211 gold badge1 silver badge3 bronze badges3 Answers
Reset to default 2There's an error in your link attribute. You can't place double-quotes inside of double-quotes without escaping them. Right now, your onclick attribute is just: "fancyConfirm("
Try:
<a href="http://www.example./" onclick="fancyConfirm('Are you sure you want to delete?');">Test</a>
Or:
<a href="http://www.example./" onclick="fancyConfirm(\"Are you sure you want to delete?\");">Test</a>
You need this instead:
<a href="#" onclick="fancyConfirm('Are you sure you want to delete?');return false;">Test</a>
That should work. The hash (#) wont show in the URL because return false;
will only make what is in the onclick
happen.
Also, I know this is obvious, but do you have Fancybox and jQuery defined on the page?
Have a look at this post,
Javascript/Jquery Callback for Fancybox Yes No Confirm
The author of fancy box has a slightly different solution and it works.
版权声明:本文标题:javascript - How can i make fancybox display a "yesno confirm box" via a href onclick? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744325163a2600691.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论