jquery制作彈窗提示窗口代碼分享
更新時(shí)間: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)閉窗口,解決自動(dòng)關(guān)閉與手動(dòng)關(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(); //獲取焦點(diǎn),以防回車(chē)后無(wú)法觸發(fā)函數(shù)
position(document.getElementById('mask_layer'),0,0);
position(document.getElementById('scs_alert'),$(window).width()/2,$(window).height()/2);
if (typeof can == "number"){
//定時(shí)關(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()}
}
//綁定回車(chē)與ESC鍵
if (document.attachEvent)
document.attachEvent("onkeydown", modal_key);
else
document.addEventListener("keydown", modal_key, true);
}
//====================================以下為測(cè)試函數(shù)=======================================//
function test1(){
scscms_alert("默認(rèn)提示信息");
}
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秒后自動(dòng)關(guān)閉","ok","",3);
}
function test10(){
scscms_alert("詢問(wèn)信息定時(shí)關(guān)閉提示信息,3秒后自動(dòng)關(guān)閉,無(wú)取消時(shí)回調(diào)函數(shù).不推薦使用。","confirm",function(){alert("確定回調(diào)用!")},3);
}
</script>
您可能感興趣的文章:
- jQuery實(shí)現(xiàn)的兩種簡(jiǎn)單彈窗效果示例
- jquery實(shí)現(xiàn)彈窗(系統(tǒng)提示框)效果
- Jquery實(shí)現(xiàn)自定義彈窗示例
- jquery ui dialog實(shí)現(xiàn)彈窗特效的思路及代碼
- 小巧強(qiáng)大的jquery layer彈窗彈層插件
- 簡(jiǎn)單實(shí)現(xiàn)jQuery彈窗效果
- jQuery實(shí)現(xiàn)彈窗居中效果類(lèi)似alert()
- jquery實(shí)現(xiàn)彈窗功能(窗口居中顯示)
- 運(yùn)用JQuery的toggle實(shí)現(xiàn)網(wǎng)頁(yè)加載完成自動(dòng)彈窗
- jquery實(shí)現(xiàn)簡(jiǎn)單的彈窗效果
相關(guān)文章
jQuery 擴(kuò)展對(duì)input的一些操作方法
擴(kuò)展對(duì)input的一些方法(練習(xí)jQuery插件)2009-10-10關(guān)于頁(yè)面加載即執(zhí)行JQuery的三種方法小結(jié)
這篇文章主要介紹了關(guān)于頁(yè)面加載即執(zhí)行JQuery的三種方法小結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10jquery dataTable 后臺(tái)加載數(shù)據(jù)并分頁(yè)實(shí)例代碼
本篇文章主要介紹了jquery dataTable 后臺(tái)加載數(shù)據(jù)并分頁(yè)實(shí)例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下2017-06-06jquery實(shí)現(xiàn)商品拖動(dòng)選擇效果代碼(自寫(xiě))
商品拖動(dòng)選擇效果如圖所示,感興趣的朋友已經(jīng)迫不及待想實(shí)現(xiàn)了吧,下面與大家分享下具體的實(shí)現(xiàn)思路及處理程序2013-05-05jQuery實(shí)現(xiàn)的簡(jiǎn)單前端搜索功能示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的簡(jiǎn)單前端搜索功能,涉及jQuery事件響應(yīng)與頁(yè)面元素遍歷、匹配、動(dòng)態(tài)設(shè)置等相關(guān)操作技巧,需要的朋友可以參考下2017-10-10jQuery學(xué)習(xí)筆記之創(chuàng)建DOM元素
這篇文章主要介紹了jQuery學(xué)習(xí)筆記之創(chuàng)建DOM元素的相關(guān)資料,需要的朋友可以參考下2015-01-01