欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

用Jquery重写windows.alert方法实现思路

程序员文章站 2022-06-20 09:50:10
已经在 ie8 , firefox3.0.11下面测试通过 . 代码如下: $.extend({ includepath: '', include: function(file)...

已经在 ie8 , firefox3.0.11下面测试通过

. 代码如下:


$.extend({
includepath: '',
include: function(file)
{
var files = typeof file == "string" ? [file] : file;
for (var i = 0; i < files.length; i++)
{
var name = files[i].replace(/^\s|\s$/g, "");
var att = name.split('.');
var ext = att[att.length - 1].tolowercase();
var iscss = ext == "css";
var tag = iscss ? "link" : "script";
var attr = iscss ? " type='text/css' rel='stylesheet' " : " language='javascript' type='text/javascript' ";
var link = (iscss ? "href" : "src") + "='" + $.includepath + name + "'";
if ($(tag + "[" + link + "]").length == 0) document.write("<" + tag + attr + link + "></" + tag + ">");
}
}
});
$.include(['script/jquery.pbox.js','/css/pop_win.css']);
$(document).ready(function()
{
var isfirstalert = true;
var alertqueue = [];
window.alert = showalert;
var palert = "";
palert += "<p style=\"width:380px; height:180px; overflow:hidden;display:none\" id=\"palert\">";
palert += " <p class=\"win_c\">";
palert += " <p class=\"win_t\" id=\"\">";
palert += " <p class=\"mail_timg\" ><h3>title<\/h3><\/p>";
palert += " <p class=\"clear\"><\/p>";
palert += " <\/p>";
palert += " <p class=\"alrt2\" style=\"text-align:center\">";
palert += " <span id=\"spaalertmessage\" class=\"f14 ifont\"><\/span><br \/>";
palert += " <p class=\"clear\"><\/p>";
palert += " <\/p>";
palert += " <p class=\"acenter\"><input id='alertclose' type=\"button\" value=\"确定\" class=\"btn7\" \/> <input type=\"reset\" value=\"取消\" style=\"display:none\" class=\"btn8\" \/><br \/><br \/><\/p>";
palert += " <p> <\/p>";
palert += " <\/p>";
palert += " ";
palert += "<\/p>";
$("body").append(palert);
function showalert(info)
{
alertqueue.push(info);
if (isfirstalert)
{
isfirstalert = false;
openalert();
}
}
$("#alertclose").click(function()
{
$('#palert').closediv()
if (alertqueue.length > 0)
{
settimeout(openalert, 150);
}
});
function openalert()
{
$("#spaalertmessage").html(alertqueue[0]);
alertqueue.splice(0, 1);
$("#palert").opendiv();
}
});


注:以上引用js与css的jquery插件