jquery制作彈窗提示窗口代碼分享
更新時間:2014年03月02日 09:36:55 作者:
jquery制作的彈窗提示窗口插件,包含多種模式。帶有回執(zhí)函數(shù)值的功能,需要的朋友可以參考下
復(fù)制代碼 代碼如下:
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<!--[if IE 6]>
<script type="text/javascript" src="js/iepngfix_tilebg.js"></script>
<![endif]-->
<script type="text/javascript">
function position(elem,l,t){
var isIE6 = !-[1,] && !window.XMLHttpRequest;
if(isIE6){
var style = elem.style,
dom = '(document.documentElement)',
left = l - document.documentElement.scrollLeft,
top = t - document.documentElement.scrollTop;
style.position = 'absolute';
style.removeExpression('left');
style.removeExpression('top');
style.setExpression('left', 'eval(' + dom + '.scrollLeft + ' + left + ') + "px"');
style.setExpression('top', 'eval(' + dom + '.scrollTop + ' + top + ') + "px"');
}else{
elem.style.position = 'fixed';
}
}
function scscms_alert(msg,sign,ok,can){
var c_=false;//是否已經(jīng)關(guān)閉窗口,解決自動關(guān)閉與手動關(guān)閉沖突
sign=sign||"";
var s="<div id='mask_layer'></div><div id='scs_alert'><div id='alert_top'></div><div id='alert_bg'><table width='260' align='center' border='0' cellspacing='0' cellpadding='1'><tr>";
if (sign!="")s+="<td width='45'><div id='inco_"+sign+"'></div></td>";
s+="<td id='alert_txt'>"+msg+"</td></tr></table>";
if (sign=="confirm"){
s+="<a href='javascript:void(0)' id='confirm_ok'>確 定</a><a href='javascript:void(0)' id='confirm_cancel'>取 消</a>";
}else{
s+="<a href='javascript:void(0)' id='alert_ok'>確 定</a>"
}
s+="</div><div id='alert_foot'></div></div>";
$("body").append(s);
$("#scs_alert").css("margin-top",-($("#scs_alert").height()/2)+"px"); //使其垂直居中
$("#scs_alert").focus(); //獲取焦點,以防回車后無法觸發(fā)函數(shù)
position(document.getElementById('mask_layer'),0,0);
position(document.getElementById('scs_alert'),$(window).width()/2,$(window).height()/2);
if (typeof can == "number"){
//定時關(guān)閉提示
setTimeout(function(){
close_info();
},can*1000);
}
function close_info(){
//關(guān)閉提示窗口
if(!c_){
$("#mask_layer").fadeOut("fast",function(){
$("#scs_alert").remove();
$(this).remove();
});
c_=true;
}
}
$("#alert_ok").click(function(){
close_info();
if(typeof(ok)=="function")ok();
});
$("#confirm_ok").click(function(){
close_info();
if(typeof(ok)=="function")ok();
});
$("#confirm_cancel").click(function(){
close_info();
if(typeof(can)=="function")can();
});
function modal_key(e){
e = e||event;
close_info();
var code = e.which||event.keyCode;
if (code == 13 || code == 32){if(typeof(ok)=="function")ok()}
if (code == 27){if(typeof(can)=="function")can()}
}
//綁定回車與ESC鍵
if (document.attachEvent)
document.attachEvent("onkeydown", modal_key);
else
document.addEventListener("keydown", modal_key, true);
}
//====================================以下為測試函數(shù)=======================================//
function test1(){
scscms_alert("默認提示信息");
}
function test2(){
scscms_alert("成功提示信息","ok");
}
function test3(){
scscms_alert("成功提示后回調(diào)函數(shù)","ok",function(){alert("回調(diào)成功!")});
}
function test4(){
scscms_alert("失敗提示信息","error");
}
function test5(){
scscms_alert("失敗提示信息","error",function(){alert("哦!no!")});
}
function test6(){
scscms_alert("警告提示信息","warn");
}
function test7(){
scscms_alert("警告提示信息","warn",function(){alert("哦!警告!")});
}
function test8(){
scscms_alert("您喜歡此信息提示嗎?","confirm",function(){
scscms_alert("您選擇了喜歡,謝謝!","ok");
},function(){
scscms_alert("您選擇了不喜歡,汗!","error");
});
}
function test9(){
scscms_alert("本信息3秒后自動關(guān)閉","ok","",3);
}
function test10(){
scscms_alert("詢問信息定時關(guān)閉提示信息,3秒后自動關(guān)閉,無取消時回調(diào)函數(shù).不推薦使用。","confirm",function(){alert("確定回調(diào)用!")},3);
}
</script>
相關(guān)文章
關(guān)于頁面加載即執(zhí)行JQuery的三種方法小結(jié)
這篇文章主要介紹了關(guān)于頁面加載即執(zhí)行JQuery的三種方法小結(jié),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-10-10jquery dataTable 后臺加載數(shù)據(jù)并分頁實例代碼
本篇文章主要介紹了jquery dataTable 后臺加載數(shù)據(jù)并分頁實例代碼,具有一定的參考價值,有興趣的可以了解一下2017-06-06jQuery學(xué)習(xí)筆記之創(chuàng)建DOM元素
這篇文章主要介紹了jQuery學(xué)習(xí)筆記之創(chuàng)建DOM元素的相關(guān)資料,需要的朋友可以參考下2015-01-01