87,909
社区成员
发帖
与我相关
我的任务
分享
//比如重写前的alert()常用方法为:
alert("这是一个输入框");
//重写后想得到用法为:
alerts("这是一个输入框");
//-----------------------------
/比如重写前的confirm()常用方法为:
if(confirm("确定删除吗?"))
{
//点击确定后执行的内容
}
else
{
//点击取消后执行的内容
}
//重写后想得到用法为:
if(confirms("确定删除吗?"))
{
//点击确定后执行的内容
}
else
{
//点击取消后执行的内容
}
(function($) {
$.alerts = {
alert: function(title, message, callback) {
if( title == null ) title = 'Alert';
$.alerts._show(title, message, null, 'alert', function(result) {
if( callback ) callback(result);
});
},
confirm: function(title, message, callback) {
if( title == null ) title = 'Confirm';
$.alerts._show(title, message, null, 'confirm', function(result) {
if( callback ) callback(result);
});
},
prompt: function(title, message, value , callback) {
if( title == null ) title = 'Prompt';
$.alerts._show(title, message, value, 'prompt', function(result) {
if( callback ) callback(result);
});
},
_show: function(title, msg, value, type, callback) {
if($("#gray").length<1)
{
var grayhtml='<!--弹出层开始-->';//自己定义了样式和显示效果
grayhtml+='<div id="gray" class="undis">';
grayhtml+='<div id="login" style="margin-top:0;">';
grayhtml+='<div class="login">';
grayhtml+='<div class="title"></div>';
grayhtml+='<div class="clear"></div>';
grayhtml+='<div class="con"></div>';
grayhtml+='<div class="foot"></div>';
grayhtml+='</div>';
grayhtml+='</div>';
grayhtml+='</div>';
grayhtml+='<!--弹出层结束-->';
$("body").prepend(grayhtml);
}
$("#gray").height(document.body.scrollHeight);
$("#gray .title").html(title);
$("#gray .con").html(msg);
$("#gray").removeClass("undis");
$("#gray").addClass("dis");
switch( type ) {
case 'alert':
$("#gray .foot").html('<input type="button" value="确定" id="popup_ok" /> ');
$("#popup_ok").click( function() {
$.alerts._hide();
callback(true);
});
$("#popup_ok").focus().keypress( function(e) {
if( e.keyCode == 13 || e.keyCode == 27 ) $("#popup_ok").trigger('click');
});
break;
case 'confirm':
$("#gray .foot").html('<input type="button" value="确定" id="popup_ok" /> <input type="button" value="取消" id="popup_cancel" />');
$("#popup_ok").click( function() {
$.alerts._hide();
if( callback ) callback(true);
});
$("#popup_cancel").click( function() {
$.alerts._hide();
if( callback ) callback(false);
});
$("#popup_ok").focus();
$("#popup_ok, #popup_cancel").keypress( function(e) {
if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
});
break;
case 'prompt':
$("#gray .con").append('<br /><input type="text" size="30" id="popup_prompt" />');
$("#gray .foot").html('<div id="popup_panel"><input type="button" value="确定" id="popup_ok" /> <input type="button" value="取消" id="popup_cancel" /></div>');
$("#popup_ok").click( function() {
var val = $("#popup_prompt").val();
if(val)
{
$.alerts._hide();
if( callback ) callback( val );
}
else
{
var err='<span class="prompterr">'+img_check_error+'不能为空!</span>';
if($(".prompterr").length<1)$("#gray .con").append(err);
}
});
$("#popup_cancel").click( function() {
$.alerts._hide();
if( callback ) callback( null );
});
$("#popup_prompt, #popup_ok, #popup_cancel").keypress( function(e) {
if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
});
if( value ) $("#popup_prompt").val(value);
$("#popup_prompt").focus().select();
break;
}
},
_hide: function() {
$("#gray").removeClass("dis");
$("#gray").addClass("undis");
}
}
// Shortuct functions
zfalert = function(title, message, callback) {
$.alerts.alert(title, message, callback);
}
zfconfirm = function(title, message, callback) {
$.alerts.confirm(title, message, callback);
};
zfprompt = function(title, message, value, callback) {
$.alerts.prompt(title, message, value, callback);
};
})(jQuery);
zfalert('提示标题','消费次数必须大于0!',function(){$("input[name='discount_postnum']").select();});
zfconfirm('提示标题','提示信息',function(r){
if(r)
{
//...点确定之后执行的内容
}
});
zfprompt('提示标题','提示信息', '', function(){});
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>baoti</title>
<style type="text/css">
#dialogbg {
top: 0;
left: 0;
width: 100%;
height: 100%;
position: fixed;
background: rgba(0,0,0,.2);
background: #0005;
}
.dialog {
width: auto;
text-align: left;
position: absolute;
min-width: 150px;
background: white;
border: 1px solid #666;
box-shadow: 2px 2px 6px rgba(0,0,0,.75);
-moz-box-shadow: 2px 2px 6px rgba(0,0,0,.75);
-webkit-box-shadow: 2px 2px 6px rgba(0,0,0,.75);
}
.dialog,.dialog btns>* {
border-radius: 5px;
-moz-border-radius: 5px;
-khtml-border-radius: 5px;
-webkit-border-radius: 5px;
behavior: url(../iefix/ie-css3.htc);
}
.dialog btns>*,.dialog .winbtns>* {
display: inline-block;
}
.dialog .title {
height: 20px;
cursor: default;
padding: 0 2px;
overflow: hidden;
line-height: 20px;
background: #0095cd;
border: solid 1px #0076a3;
border-radius-topleft: 5px;
border-radius-topright: 5px;
-moz-border-radius-topleft: 5px;
-moz-border-radius-topright: 5px;
-webkit-border-top-left-radius: 5px;
-webkit-border-top-right-radius: 5px;
background: -moz-linear-gradient(top, #00aaee, #0066cc);
background: -webkit-gradient(linear, left top, left bottom, from(#00aaee), to(#0066cc));
}
.dialog .title img{
max-width: 16px;
max-height: 16px;
margin: 0px 5px;
}
.dialog .winbtns {
top: 0;
right: 0;
position: absolute;
}
.dialog .winbtns>* {
display: inline-block;
width: 16px;
height: 15px;
overflow: hidden;
margin-top: 3px;
margin-right: 3px;
background: url(btns.gif);
}
.dialog .winbtns .min {
background-position: 0 120px;
}
.dialog .winbtns .min:hover {
background-position: 0 105px;
}
.dialog .winbtns .size {
background-position: 0 90px;
}
.dialog .winbtns .size:hover {
background-position: 0 75px;
}
.dialog .winbtns .max {
background-position: 0 60px;
}
.dialog .winbtns .max:hover {
background-position: 0 45px;
}
.dialog .winbtns .close {
background-position: 0 30px;
}
.dialog .winbtns .close:hover {
background-position: 0 15px;
}
.dialog .content {
margin: 10px;
}
.dialog input {
width: 100%;
}
.dialog .btns {
text-align: center;
margin: 10px 0;
}
.dialog .btns a {
color: #000;
width: 50px ;
height: 20px ;
margin: 0 5px;
text-decoration: none;
border: 1px solid #CCC;
}
#dialogbg, .dialog,.dialog .winbtns .size,.dialog input {
display: none ;
}
</style>
</head>
<body>
gdfgioersjkgti
<script type="text/javascript" src="../ie7/IE9.js"></script>
<script>
var dialogbg;
if(!dialogbg){
document.write('<div id="dialogbg"><div class="dialog"><div class="title"><img src="../../iboy.gif" width="9" height="12">TITLE</div><div class="winbtns"><a class="min" title="最小化" href="#"></a><a class="size" title="向下还原" href="#"></a><a class="max" title="最大化" href="#"></a><a class="close" title="关闭" href="#"></a></div><div class="content">fdgdfdfgfdgdfgdfgdfgdfgdfgdgdfgg<input type="text"></div><div class="btns"><a class="ok" href="#">确定</a><a class="cancel" href="#">取消</a></div></div></div>');
dialogbg = document.getElementById("dialogbg");
}
var dialog = dialogbg.firstChild;
var titleBar = dialog.firstChild;
var winbtns = titleBar.nextSibling;
var content = winbtns.nextSibling;
var textBox = content.lastChild;
var btns = content.nextSibling;
var btnMin = winbtns.firstChild;
var btnSize = btnMin.nextSibling;
var btnMax = btnSize.nextSibling;
var btnClose = btnMax.nextSibling;
var btnOk = btns.firstChild;
var btnCancel = btns.lastChild;
btnMin.hideFocus = true;
btnSize.hideFocus = true;
btnMax.hideFocus = true;
btnClose.hideFocus = true;
btnOk.hideFocus = true;
btnCancel.hideFocus = true;
var onDrag;
var pos = {};
function rsSize(){
pos.top = (dialogbg.offsetHeight - dialog.offsetHeight) / 2;
pos.left = (dialogbg.offsetWidth - dialog.offsetWidth) / 2;
dialog.style.width = dialog.style.height = "auto";
dialog.style.left = pos.left + "px";
dialog.style.top = pos.top + "px";
}
var callBackFun;
var returnValue;
function dialogClose(){
dialogbg.style.display = dialog.style.display = "none";
document.documentElement.style.overflow = "auto";
if(callBackFun){
callBackFun(returnValue);
}
return false;
}
btnClose.onclick = btnCancel.onclick = dialogClose;
btnMax.onclick = function(){
dialog.style.top = dialog.style.left = 0;
btnSize.style.display = "inline-block";
btnMax.style.display = "none";
dialog.style.height = "100%";
dialog.style.width = "100%";
return false;
}
btnSize.onclick = function(){
btnMax.style.display = "inline-block"
btnSize.style.display = "none";
rsSize();
return false;
}
btnOk.onclick = function(){
if(callBackFun){
if(textBox.style.display == "none"){
returnValue = true;
}else{
returnValue = textBox.value;
}
}
dialogClose();
return false;
}
titleBar.onmousedown = function(){
onDrag = true;
}
titleBar.onmouseup = function(){
onDrag = false;
}
titleBar.onselectstart = function(){
return false;
}
dialogbg.onmousemove = function(e){
if(!e){
e = window.event;
e.pageX = e.clientX + document.body.scrollLeft;
e.pageY = e.clientY + document.body.scrollTop;
}
if(onDrag == true){
pos.top += e.pageY - pos.y;
pos.left += e.pageX - pos.x;
dialog.style.top = pos.top + "px";
dialog.style.left = pos.left + "px";
}
pos.y = e.pageY;
pos.x = e.pageX;
}
function show(){
dialogbg.style.display = dialog.style.display = "block";
document.documentElement.style.overflow = "hidden";
rsSize();
}
function msg(msgStr, titleStr, callBack, defaultStr){
btnMin.style.display = btnMax.style.display = "none";
titleBar.innerHTML = titleStr || "Message Box";
btnOk.style.display = "inline-block";
btns.style.display = "block";
//content.firstChild.textContent = msgStr;
if(callBack == undefined){
btnCancel.style.display = "none";
callBackFun = null;
}else{
callBackFun = callBack;
btnCancel.style.display = "inline-block";
if(defaultStr == undefined){
textBox.style.display = "none";
returnValue = false;
}else{
textBox.style.display = "block";
textBox.value = defaultStr;
returnValue = null;
}
}
show();
}
msg("点击确定或取消", "msg函数演示", function(e){
alert(e);
}, "123456");
</script>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>baoti</title>
<style type="text/css">
#dialogbg {
top: 0;
left: 0;
width: 100%;
height: 100%;
position: fixed;
background: rgba(0,0,0,.2);
background: #0005;
}
.dialog {
width: auto;
text-align: left;
position: absolute;
min-width: 150px;
background: white;
border: 1px solid #666;
box-shadow: 2px 2px 6px rgba(0,0,0,.75);
-moz-box-shadow: 2px 2px 6px rgba(0,0,0,.75);
-webkit-box-shadow: 2px 2px 6px rgba(0,0,0,.75);
}
.dialog,.dialog btns>* {
border-radius: 5px;
-moz-border-radius: 5px;
-khtml-border-radius: 5px;
-webkit-border-radius: 5px;
behavior: url(../iefix/ie-css3.htc);
}
.dialog btns>*,.dialog .winbtns>* {
display: inline-block;
}
.dialog .title {
height: 20px;
cursor: default;
padding: 0 2px;
overflow: hidden;
line-height: 20px;
background: #0095cd;
border: solid 1px #0076a3;
border-radius-topleft: 5px;
border-radius-topright: 5px;
-moz-border-radius-topleft: 5px;
-moz-border-radius-topright: 5px;
-webkit-border-top-left-radius: 5px;
-webkit-border-top-right-radius: 5px;
background: -moz-linear-gradient(top, #00aaee, #0066cc);
background: -webkit-gradient(linear, left top, left bottom, from(#00aaee), to(#0066cc));
}
.dialog .title img{
max-width: 16px;
max-height: 16px;
margin: 0px 5px;
}
.dialog .winbtns {
top: 0;
right: 0;
position: absolute;
}
.dialog .winbtns>* {
display: inline-block;
width: 16px;
height: 15px;
overflow: hidden;
margin-top: 3px;
margin-right: 3px;
background: url(btns.gif);
}
.dialog .winbtns .min {
background-position: 0 120px;
}
.dialog .winbtns .min:hover {
background-position: 0 105px;
}
.dialog .winbtns .size {
background-position: 0 90px;
}
.dialog .winbtns .size:hover {
background-position: 0 75px;
}
.dialog .winbtns .max {
background-position: 0 60px;
}
.dialog .winbtns .max:hover {
background-position: 0 45px;
}
.dialog .winbtns .close {
background-position: 0 30px;
}
.dialog .winbtns .close:hover {
background-position: 0 15px;
}
.dialog .content {
margin: 10px;
}
.dialog input {
width: 100%;
}
.dialog .btns {
text-align: center;
margin: 10px 0;
}
.dialog .btns a {
color: #000;
width: 50px ;
height: 20px ;
margin: 0 5px;
text-decoration: none;
border: 1px solid #CCC;
}
#dialogbg, .dialog,.dialog .winbtns .size,.dialog input {
display: none ;
}
</style>
</head>
<body>
gdfgioersjkgti
<script type="text/javascript" src="../ie7/IE9.js"></script>
<script>
var dialogbg;
if(!dialogbg){
document.write('<div id="dialogbg"><div class="dialog"><div class="title"><img src="../../iboy.gif" width="9" height="12">TITLE</div><div class="winbtns"><a class="min" title="最小化" href="#"></a><a class="size" title="向下还原" href="#"></a><a class="max" title="最大化" href="#"></a><a class="close" title="关闭" href="#"></a></div><div class="content">fdgdfdfgfdgdfgdfgdfgdfgdfgdgdfgg<input type="text"></div><div class="btns"><a class="ok" href="#">确定</a><a class="cancel" href="#">取消</a></div></div></div>');
dialogbg = document.getElementById("dialogbg");
}
var dialog = dialogbg.firstChild;
var titleBar = dialog.firstChild;
var winbtns = titleBar.nextSibling;
var content = winbtns.nextSibling;
var textBox = content.lastChild;
var btns = content.nextSibling;
var btnMin = winbtns.firstChild;
var btnSize = btnMin.nextSibling;
var btnMax = btnSize.nextSibling;
var btnClose = btnMax.nextSibling;
var btnOk = btns.firstChild;
var btnCancel = btns.lastChild;
btnMin.hideFocus = true;
btnSize.hideFocus = true;
btnMax.hideFocus = true;
btnClose.hideFocus = true;
btnOk.hideFocus = true;
btnCancel.hideFocus = true;
var onDrag;
var pos = {};
function rsSize(){
pos.top = (dialogbg.offsetHeight - dialog.offsetHeight) / 2;
pos.left = (dialogbg.offsetWidth - dialog.offsetWidth) / 2;
dialog.style.width = dialog.style.height = "auto";
dialog.style.left = pos.left + "px";
dialog.style.top = pos.top + "px";
}
var callBackFun;
var returnValue;
function dialogClose(){
dialogbg.style.display = dialog.style.display = "none";
document.documentElement.style.overflow = "auto";
if(callBackFun){
callBackFun(returnValue);
}
return false;
}
btnClose.onclick = btnCancel.onclick = dialogClose;
btnMax.onclick = function(){
dialog.style.top = dialog.style.left = 0;
btnSize.style.display = "inline-block";
btnMax.style.display = "none";
dialog.style.height = "100%";
dialog.style.width = "100%";
return false;
}
btnSize.onclick = function(){
btnMax.style.display = "inline-block"
btnSize.style.display = "none";
rsSize();
return false;
}
btnOk.onclick = function(){
if(callBackFun){
if(textBox.style.display == "none"){
returnValue = true;
}else{
returnValue = textBox.value;
}
}
dialogClose();
return false;
}
titleBar.onmousedown = function(){
onDrag = true;
}
titleBar.onmouseup = function(){
onDrag = false;
}
titleBar.onselectstart = function(){
return false;
}
dialogbg.onmousemove = function(e){
if(!e){
e = window.event;
e.pageX = e.clientX + document.body.scrollLeft;
e.pageY = e.clientY + document.body.scrollTop;
}
if(onDrag == true){
pos.top += e.pageY - pos.y;
pos.left += e.pageX - pos.x;
dialog.style.top = pos.top + "px";
dialog.style.left = pos.left + "px";
}
pos.y = e.pageY;
pos.x = e.pageX;
}
function show(){
dialogbg.style.display = dialog.style.display = "block";
document.documentElement.style.overflow = "hidden";
rsSize();
}
function msg(msgStr, titleStr, callBack, defaultStr){
btnMin.style.display = btnMax.style.display = "none";
titleBar.innerHTML = titleStr || "Message Box";
btnOk.style.display = "inline-block";
btns.style.display = "block";
//content.firstChild.textContent = msgStr;
if(callBack == undefined){
btnCancel.style.display = "none";
callBackFun = null;
}else{
callBackFun = callBack;
btnCancel.style.display = "inline-block";
if(defaultStr == undefined){
textBox.style.display = "none";
returnValue = false;
}else{
textBox.style.display = "block";
textBox.value = defaultStr;
returnValue = null;
}
}
show();
}
msg("点击确定或取消", "msg函数演示", function(e){
alert(e);
}, "123456");
</script>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
asdasdasd<br>
</body>
</html>