功能要求:
1.仅仅重写如题三种方法的界面,使之在各浏览器中显示效果一致
2.对于上述方法中的某些方法的断点特性,要保留。比如alert();执行时,不点击确定按钮,在此方法后面的代码不执行。
3.重写后的方法,要尽量与原始js的方法的用法,切不可使原有程序有大的改动。
4.最大的愿望就是只是对方法名的改动,顶多再多加一两个参数。
5.可以用jquery来重写,如果仿官方的例子就免了。
6.再次拜谢了。
//比如重写前的alert()常用方法为:
alert("这是一个输入框");//重写后想得到用法为:
alerts("这是一个输入框");//-----------------------------/比如重写前的confirm()常用方法为:
if(confirm("确定删除吗?"))
{
//点击确定后执行的内容
}
else
{
//点击取消后执行的内容
}//重写后想得到用法为:
if(confirms("确定删除吗?"))
{
//点击确定后执行的内容
}
else
{
//点击取消后执行的内容
}
1.仅仅重写如题三种方法的界面,使之在各浏览器中显示效果一致
2.对于上述方法中的某些方法的断点特性,要保留。比如alert();执行时,不点击确定按钮,在此方法后面的代码不执行。
3.重写后的方法,要尽量与原始js的方法的用法,切不可使原有程序有大的改动。
4.最大的愿望就是只是对方法名的改动,顶多再多加一两个参数。
5.可以用jquery来重写,如果仿官方的例子就免了。
6.再次拜谢了。
//比如重写前的alert()常用方法为:
alert("这是一个输入框");//重写后想得到用法为:
alerts("这是一个输入框");//-----------------------------/比如重写前的confirm()常用方法为:
if(confirm("确定删除吗?"))
{
//点击确定后执行的内容
}
else
{
//点击取消后执行的内容
}//重写后想得到用法为:
if(confirms("确定删除吗?"))
{
//点击确定后执行的内容
}
else
{
//点击取消后执行的内容
}
用div模拟对话框吧
由于ExtJS的alert是异步执行的不会产生阻塞,因此要将用户确认后才执行的代码放在回调函数中,否则在用户确认后续代码就会执行造成不必要的错误,这一点需要我们注意的。也许重写后的只能将后面的代码放在回调函数中?也就意味着,程序结构必须大变?
alerts();//重写了alert();
}
以此类推
楼主记得结贴
msg(msgStr,function(value){
alert(您输入的值:+ value);
},defaultStr);confirm改变为
msg(msgStr,function(value){
if(value){
//点击了是
}else{
//点击了否
}
});alert改变为
msg(msgStr);IE太麻烦了,暂时还不支持。<!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>
msg(msgStr,function(value){
alert(您输入的值:+ value);
},defaultStr);confirm改变为
msg(msgStr,function(value){
if(value){
//点击了是
}else{
//点击了否
}
});alert改变为
msg(msgStr);IE太麻烦了,暂时还不支持。<!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>
如果真要实现的话,我建议你用DIV模仿一个吧!
模态窗口:非标准,只在ie下有效
通常用div 模拟 confirm都是传递 : 标题,内容,确定时执行的函数,取消(关闭)时执行的函数来实现的!绝对实现不了:if(confirm("确定删除吗?"))
{
//点击确定后执行的内容
}
else
{
//点击取消后执行的内容
}
下面是一个 例子:
http://blog.csdn.net/hch126163/archive/2010/11/05/5989554.aspx
我同意13楼的看法。
jquery的dialog插件,也不错,可以选择一下。
我现在改用了一个前人写的一个jquery的插件,具体名字忘了,发下代码,看一下吧(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(){});
此插件来源于互联网好了,结贴,给分,大家辛苦了!