首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

模拟JS的CONFIRM有关问题

2012-03-17 
模拟JS的CONFIRM问题代码是这样的,//oofunctionoo(obj){returntypeof(obj) string ?document.getEleme

模拟JS的CONFIRM问题
代码是这样的,
//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> &nbsp; </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( "往下执行的代码! ");//这里是一定要等用户点确定后才能执行的代码
}


到底应该怎么做呢????????????????????????????


[解决办法]
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);
}
}
}

热点排行