当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 用Jquery重写windows.alert方法实现思路

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

2018年09月12日  | 移动技术网IT编程  | 我要评论

已经在 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插件

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网