(function ($) { $(function () { var timeoutid = null; $("body").find(":submit,:image,a").bind("click", function (event) { var $this = $(this); cleartimeout(timeoutid); timeoutid = settimeout(function () { if ($currentdialog && !$currentdialog.data("dialog-target")) { $currentdialog.data("dialog-target", $this) } }, 500) }) }); var $currentdialog = null; var defaultoptions = { message: "", wrapper: "

", title: "系统提示", width: 300, height: "auto" }; $.confirm = function (message, options, ok, cancel) { if ($.isfunction(options)) { cancel = ok; ok = options; options = defaultoptions } options = $.extend({}, defaultoptions, { buttons: { "取消": cancel || function () { return false }, "确定": ok || function () { var $target = $dialog.data("dialog-target"); if ($target) { if ($target.is("a")) { var href = $target.attr("href"); if (href.indexof("javascript:") != -1) { eval(href.substring(11)) } } else { if ($target.is(":submit,:image")) { $target.parents("form").eq(0).find("#__eventtarget").val($target.attr("name")).end().submit() } } } } } }, options); options.message = message; var $dialog = $("

").attr("title", options.title); $currentdialog = $dialog; var msg = options.message; var $message = $(options.wrapper).html(msg.tostring()); var distroy = function () { $dialog.dialog("destroy"); $currentdialog = null }; $.each(options.buttons, function (name, fn) { options.buttons[name] = function () { fn(); distroy() } }); $dialog.append($message).dialog({ bgiframe: true, width: options.width, height: options.height, modal: true, buttons: options.buttons, close: function () { distroy() } }); return false }; $.alert = function (message, options, ok) { if ($.isfunction(options)) { ok = options } options = $.extend({}, options, { buttons: { "确定": ok || function () { return false } } }); return $.confirm(message, options) }; window.__confirm = window.confirm; window.__alert = window.alert; window.confirm = $.confirm; window.alert = $.alert })(jquery);