用Jquery重寫windows.alert方法實(shí)現(xiàn)思路
更新時間:2013年04月03日 16:27:37 作者:
本文將介紹下用Jquery重寫windows.alert方法,已經(jīng)在 IE8 , firefox3.0.11下面測試通過,喜歡的朋友可以放心使用
已經(jīng)在 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.divbox.js','/css/pop_win.css']);
$(document).ready(function()
{
var IsFirstAlert = true;
var alertQueue = [];
window.alert = showAlert;
var divalert = "";
divalert += "<div style=\"width:380px; height:180px; overflow:hidden;display:none\" id=\"divAlert\">";
divalert += " <div class=\"win_c\">";
divalert += " <div class=\"win_t\" id=\"\">";
divalert += " <div class=\"mail_timg\" ><h3>TITLE<\/h3><\/div>";
divalert += " <div class=\"clear\"><\/div>";
divalert += " <\/div>";
divalert += " <div class=\"alrt2\" style=\"text-align:center\">";
divalert += " <span id=\"spaAlertMessage\" class=\"f14 ifont\"><\/span><br \/>";
divalert += " <div class=\"clear\"><\/div>";
divalert += " <\/div>";
divalert += " <p class=\"Acenter\"><input id='alertClose' type=\"button\" value=\"確定\" class=\"btn7\" \/> <input type=\"reset\" value=\"取消\" style=\"display:none\" class=\"btn8\" \/><br \/><br \/><\/p>";
divalert += " <p> <\/p>";
divalert += " <\/div>";
divalert += " ";
divalert += "<\/div>";
$("body").append(divalert);
function showAlert(info)
{
alertQueue.push(info);
if (IsFirstAlert)
{
IsFirstAlert = false;
OpenAlert();
}
}
$("#alertClose").click(function()
{
$('#divAlert').CloseDiv()
if (alertQueue.length > 0)
{
setTimeout(OpenAlert, 150);
}
});
function OpenAlert()
{
$("#spaAlertMessage").html(alertQueue[0]);
alertQueue.splice(0, 1);
$("#divAlert").OpenDiv();
}
});
注:以上引用js與CSS的jquery插件
復(fù)制代碼 代碼如下:
$.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.divbox.js','/css/pop_win.css']);
$(document).ready(function()
{
var IsFirstAlert = true;
var alertQueue = [];
window.alert = showAlert;
var divalert = "";
divalert += "<div style=\"width:380px; height:180px; overflow:hidden;display:none\" id=\"divAlert\">";
divalert += " <div class=\"win_c\">";
divalert += " <div class=\"win_t\" id=\"\">";
divalert += " <div class=\"mail_timg\" ><h3>TITLE<\/h3><\/div>";
divalert += " <div class=\"clear\"><\/div>";
divalert += " <\/div>";
divalert += " <div class=\"alrt2\" style=\"text-align:center\">";
divalert += " <span id=\"spaAlertMessage\" class=\"f14 ifont\"><\/span><br \/>";
divalert += " <div class=\"clear\"><\/div>";
divalert += " <\/div>";
divalert += " <p class=\"Acenter\"><input id='alertClose' type=\"button\" value=\"確定\" class=\"btn7\" \/> <input type=\"reset\" value=\"取消\" style=\"display:none\" class=\"btn8\" \/><br \/><br \/><\/p>";
divalert += " <p> <\/p>";
divalert += " <\/div>";
divalert += " ";
divalert += "<\/div>";
$("body").append(divalert);
function showAlert(info)
{
alertQueue.push(info);
if (IsFirstAlert)
{
IsFirstAlert = false;
OpenAlert();
}
}
$("#alertClose").click(function()
{
$('#divAlert').CloseDiv()
if (alertQueue.length > 0)
{
setTimeout(OpenAlert, 150);
}
});
function OpenAlert()
{
$("#spaAlertMessage").html(alertQueue[0]);
alertQueue.splice(0, 1);
$("#divAlert").OpenDiv();
}
});
注:以上引用js與CSS的jquery插件
您可能感興趣的文章:
- jquery.alert 彈出式復(fù)選框?qū)崿F(xiàn)代碼
- 基于jQuery的彈出消息插件 DivAlert之旅(一)
- 基于jQuery的消息提示插件 DivAlert之旅(二)
- JQuery的Alert消息框插件使用介紹
- jQuery)擴(kuò)展jQuery系列之一 模擬alert,confirm(一)
- 基于jquery的彈出提示框始終處于窗口的居中位置(類似于alert彈出框的效果)
- jQuery綁定事件不執(zhí)行但alert后可以正常執(zhí)行
- 自編jQuery插件實(shí)現(xiàn)模擬alert和confirm
- jQuery提示插件alertify使用指南
- jquery SweetAlert插件實(shí)現(xiàn)響應(yīng)式提示框
- jQuery實(shí)現(xiàn)摸擬alert提示框
相關(guān)文章
php結(jié)合imgareaselect實(shí)現(xiàn)圖片裁剪
這篇文章主要介紹了php結(jié)合imgareaselect實(shí)現(xiàn)圖片裁剪的相關(guān)資料,需要的朋友可以參考下2015-07-07jquery下將選擇的checkbox的id組成字符串的方法
jquery下將選擇的checkbox的id組成字符串的方法,需要的朋友可以參考下。2010-11-11jquery異步調(diào)用頁面后臺方法‏(asp.net)
給出了兩個簡單的例子,無參數(shù)的和有參數(shù)的,返回的都是json數(shù)據(jù)。2011-03-03基于jquery-resizable創(chuàng)建可調(diào)整大小的表(table)格
本文介紹如何基于jquery-resizable實(shí)現(xiàn)可調(diào)整表格(table)列寬的代碼,需要的朋友可以參考下2023-06-06jquery實(shí)現(xiàn)靜態(tài)搜索功能(可輸入搜索文字)
本文主要介紹了jquery實(shí)現(xiàn)靜態(tài)搜索功能的示例代碼,可通過輸入搜索文字進(jìn)行篩選信息。具有很好的參考價(jià)值,下面跟著小編一起來看下吧2017-03-03