模拟JS的CONFIRM问题

qiyeziyan 2007-03-09 04:29:40
代码是这样的,
//oo
function oo(obj){
return typeof(obj)=="string"?document.getElementById(obj):obj;
}
function ofocu(obj){
window.tmpObj=oo(obj);
window.setTimeout("window.tmpObj.focus()",100);
}

function ShowConfirm(caption){
var l,w,h,x,y,i,n,bg,o;
w=284;
h=194;
x=(document.body.clientWidth-w)/2;
y=(document.body.clientHeight-h)/2+document.body.scrollTop;
o=document.createElement("div");
o.style.cssText="display:none;z-index:99;position:absolute;left:0;top:0;width:100%;height:"+document.body.scrollHeight+";background:url(blank.gif)";
o.id="conMsg";
document.body.appendChild(o);
l="<div style=cursor:default;position:absolute;left:"+x+";top:"+y+";width:"+w+";height:"+h+">";
bg="filter:progid:dximagetransform.microsoft.alphaimageloader(src=DBS_Images/bg_msg.png)";
if(navigator.userAgent.indexOf("IE 5.0")>0){
bg="background:url(DBS_Images/bg_msg.png)";
}
if(window.Event){
bg="background:url(DBS_Images/bg_msg.png)";
}
l+="<iframe src=\"javascript:false\" style=\"position:absolute; visibility:inherit; top:0px; left:0px; width:100%; height:100%; z-index:-1; border:0; filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';\"></iframe><div style=position:absolute;width:100%;height:100%;"+bg+"></div>";
l+="<div onselectstart=return(false) onmousedown=this.parentNode.parentNode.drag_start(event) align=right style=position:absolute;height:27;width:100%;cursor:move;>";
l+="<button onclick=\"oo('conMsg').style.display='none';\" mode=10,10,3,btdlgclose style='margin-top:9;margin-right:14'></button></div>";
l+="<button id=btDlgOk onclick=\"oo('conMsg').style.display='none';\" mode=72,25,3,bg_btn style=position:absolute;left:55;top:153>确定</button>";
l+="<button id=btDlgCel onclick=\"oo('conMsg').style.display='none';\" mode=72,25,3,bg_btn style=position:absolute;left:140;top:153>取消</button>";
l+="<table cellspadding=0 cellspacing=0 width=160 height=60 style=position:absolute;left:94;top:54;font-size:12>";
l+="<tr><td id=conMsg_caption style=line-height:18px> </td></tr></table>";
l+="</div>";
o.innerHTML=l;
ButtonRef();
o.oncontextmenu=o.onselectstart=function(){return false}
o.onmouseup=function(){this.isDrag=null}
o.drag_start=function(e){
this.isDrag=1;
this.dragPx=this.childNodes[0].offsetLeft;
this.dragPy=this.childNodes[0].offsetTop;
this.dragSx=e.screenX;
this.dragSy=e.screenY;
}
o.onmousemove=function(e){
e=e==null?event:e;
if(this.isDrag==1){
this.childNodes[0].style.left=this.dragPx+e.screenX-this.dragSx;
this.childNodes[0].style.top=this.dragPy+e.screenY-this.dragSy;
}
}
oo("conMsg").style.display="";
oo("conMsg_caption").innerHTML=caption;
ofocu("btDlgCel");
}


function ButtonRef(){
var ol=document.getElementsByTagName("BUTTON"),i,mode,a;
for(i=0;i<ol.length;i++){
mode=ol[i].getAttribute("mode");
if(mode!=""&&mode!=null){
a=mode.split(",");
ol[i].style.fontSize=12;
ol[i].hideFocus=true;
ol[i].style.cssText+=";border:0;cursor:hand;cursor:pointer;line-height:"+(a[1]*1+2)+"px;background:url(DBS_Images/"+a[3]+".gif) repeat-y";
ol[i].style.width=a[0];
ol[i].style.height=a[1];
ol[i].setAttribute("mode",null);
ol[i].size=a[2];
ol[i].sel=function(index){this.style.backgroundPosition="0 "+(this.offsetHeight*(this.size-index))}
if(navigator.userAgent.indexOf("IE")==-1){
ol[i].type=ol[i].name=="submit"?"submit":"button";
}
if(a[4]=="d"){
continue;
}
ol[i].onmouseover=ol[i].onmouseout=ol[i].onmousedown=ol[i].onmouseup=function(e){
var n=this.size,y=0,cmd=this.getAttribute("cmd");
e=e==null?event:e;
if(e.type=="mouseup"&&cmd!=null){
btClick(cmd);
}
if((n==1&&"mouseover,mouseout".inc(e.type))||(n==2&&"mousedown,mouseup".inc(e.type))){
return;
}
if(e.type=="mouseout"){
y=0;
}
if(e.type=="mouseover"||e.type=="mouseup"){
y=(n==2?1:2)*this.offsetHeight;
}
if(e.type=="mousedown"){
y=this.offsetHeight;
}
this.style.backgroundPosition="0 "+y;
}
}
}
}

function Del(){
ShowConfirm();
//请问在这里怎么判断ShowConfirm()之后,用户点的是什么,才能往下执行???如果用户点击取消,只隐藏divConfrim就行了,如果是确定那么就往下执行。
alert("往下执行的代码!");//这里是一定要等用户点确定后才能执行的代码
}


到底应该怎么做呢????????????????????????????
...全文
444 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ziyan_suo 2007-03-12
  • 打赏
  • 举报
回复
l+="<button id=btDlgOk onclick=\"oo('conMsg').style.display='none';eval('"+fun+"(true)');\" mode=72,25,3,bg_btn style=position:absolute;left:55;top:153>确定</button>";
l+="<button id=btDlgCel onclick=\"oo('conMsg').style.display='none';eval('"+fun+"(false)');\" mode=72,25,3,bg_btn style=position:absolute;left:140;top:153>取消</button>";

function DropDataBases(bool){
if(bool == null){
ShowConfirm("确定要删除所选数据库吗?","DropDataBases");
}
else{
if(bool){
alert("删除数据库");
return false;
var arrKey = new Array("act","dbName");
var arrPostValue = new Array("10005",dbName.substr(0,dbName.length-1));
var objAjax = new AJAX("DBS_Proc/DBS_Admin_ShowDataBases.php",DropDataBasesBack);
objAjax.Post(arrKey,arrPostValue);
}
}
}
mmcgzs 2007-03-10
  • 打赏
  • 举报
回复
感觉应该这样实现:

ShowConfirm(callback);

function callback()
{
alert("clickOk");
}

传一个函数进去,ok的时候调用该函数
tantaiyizu 2007-03-09
  • 打赏
  • 举报
回复
自带的不用,真是不知所云..
qiyeziyan 2007-03-09
  • 打赏
  • 举报
回复
ButtonRef实际上就是把<button标签替换成了<input type='button'

真真工作的就是ShowConfirm()这个函数,这两句就是“确定”和“取消”

l+="<button id=btDlgOk onclick=\"oo('conMsg').style.display='none';\" mode=72,25,3,bg_btn style=position:absolute;left:55;top:153>确定</button>";
l+="<button id=btDlgCel onclick=\"oo('conMsg').style.display='none';\" mode=72,25,3,bg_btn style=position:absolute;left:140;top:153>取消</button>";

点击确定和取消按扭后,这个conMsg(div)就关闭,mode 的值不用管,其它的没有什么了,就是想在另一个函数(Del)里知道用户是点的什么,然后作出相应的处理,再用户还没有点击时,那个Del函数里不能执行其它的代码。。。。。求高人相助!!!!
BlueDestiny 2007-03-09
  • 打赏
  • 举报
回复
http://www.never-online.net/code/js/SimulateModalDialog/
he_8134 2007-03-09
  • 打赏
  • 举报
回复
那么长的代码,分数再多也不干...楼主应该增强一下描述能力..

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧