信息提示插件

稿件来源: 阳光企业网站管理系统   撰稿作者: 太阳光   发表日期: 2012-02-23   阅读次数: 387   查看权限: 游客查看

网页默认的alert提示信息窗口比较难看,特别是firefox的。所以制作网页中常常需要自己定制一个提示窗口。

  测试:点击进入测试页内置IE6下PNG透明最佳方法!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>scscms-信息提示插件</title>
<meta name="keywords" content="信息提示插件" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="信息提示插件" />
<script type="text/javascript" src="images/jquery-1.7.1.min.js"></script>
<!--[if IE 6]>
<script type="text/javascript" src="images/iepngfix_tilebg.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="images/plug.css">
<script type="text/javascript">
/*弹出信息参数设置: msg:提示信息内容; sign:(ok:成功)(warn:警告)(error:错误)(confirm:询问)或者为空; ok:确定后回调函数; can:取消后回调函数,如果是数字就表示定时关闭提示的秒数
作者:太阳光
邮箱:guangda1234@126.com
说明:本程序是本人因工作需要原创,欢迎拍砖或者修改。如果有更好的改进请发一份给我学习,也欢迎拿去使用!
修改时间:2012-3-13
*/
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;//是否已经关闭窗口,解决自动关闭与手动关闭冲突
	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(); //获取焦点,以防回车后无法触发函数
	position(document.getElementById('mask_layer'),0,0);
	position(document.getElementById('scs_alert'),$(window).width()/2,$(window).height()/2);
	if (typeof can == "number"){
	//定时关闭提示
		setTimeout(function(){
			close_info();
		},can*1000);
	}
	function close_info(){
	//关闭提示窗口
		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);
}

//====================================以下为测试函数=======================================//
function test1(){
	scscms_alert("默认提示信息");
}
function test2(){
	scscms_alert("成功提示信息","ok");
}
function test3(){
	scscms_alert("成功提示后回调函数","ok",function(){alert("回调成功!")});
}
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秒后自动关闭","ok","",3);
}
function test10(){
	scscms_alert("询问信息定时关闭提示信息,3秒后自动关闭,无取消时回调函数.不推荐使用。","confirm",function(){alert("确定回调用!")},3);
}
</script>
</head>
<body>
<button type="button" onclick="test1()">默认提示信息</button><br/>
<button type="button" onclick="test2()">成功提示信息</button><br/>
<button type="button" onclick="test3()">成功提示后回调函数</button><br/>
<button type="button" onclick="test4()">失败提示信息</button><br/>
<button type="button" onclick="test5()">失败提示后回调函数</button><br/>
<button type="button" onclick="test6()">警告提示信息</button><br/>
<button type="button" onclick="test7()">警告提示后回调函数</button><br/>
<button type="button" onclick="test8()">询问信息</button><br/>
<button type="button" onclick="test9()">定时关闭提示信息</button><br/>
<button type="button" onclick="test10()">询问信息定时关闭提示信息</button><br/>
<div style="height:1800px;background:url(images/scs_alert.png) no-repeat center"></div>
</body>
</html>

下载地址:http://www.scscms.com/software/2012-2/2411109408.html

关键词: alert,信息提示,插件   编辑时间: 2012-03-20

  • 感到高兴

    0

    高兴
  • 感到支持

    0

    支持
  • 感到搞笑

    0

    搞笑
  • 感到不解

    0

    不解
  • 感到谎言

    0

    谎言
  • 感到枪稿

    0

    枪稿
  • 感到震惊

    0

    震惊
  • 感到无奈

    0

    无奈
  • 感到无聊

    0

    无聊
  • 感到反对

    0

    反对
  • 感到愤怒

    0

    愤怒
100%(1)
0%(0)
共有0 条评论 发言请遵守【相关规定

网友评论

会员头像
发 表同步腾讯微博    验证码:  点击更新请先登陆
  • 暂无评论
关闭模块文章图片 article Pictrue
  • 我的妈妈爸爸
  • 基于koa2+mysql+vue2.0+Element阳光内容管理系统
  • 代码覆盖率工具 Istanbul 入门教程
  • 全栈工程师的武器——MEAN
  • 9款超炫的 CSS3 复选框(Checkbox)
  • 微信开发在线翻译功能
  • CSS3那些不为人知的高级属性
  • 给easyui的datebox添加清空事件
  • flash写字效果
  • kendoUI系列教程之DropDownList下拉菜单
  • kendoUI系列教程之datetimepicker日期时间选择
  • kendoUI系列教程之datepicker日期选择
  • kendoUI系列教程之combobox下拉列表框
  • kendoUI系列教程之colorpicker
  • kendoUI系列教程之calendar日历表
  • kendoUI系列教程之autocomplete自动补齐