<script>
function ShowConfirm(){
  oDiv = document.createElement("div");
  oDiv.id = "divConfirm";
  oDiv.style.cssText="display:none;z-index:99;position:absolute;left:200;top:200;width:100%;height:"+document.body.scrollHeight+";";
  str = "<input type='button' value='确定' onClick=\"document.getElementById('divConfirm').style.display='none';\">";
  str += "<input type='button' value='取消'>";  oDiv.innerHTML = str;
  document.body.appendChild(oDiv);
oDiv.style.display='';
}
function Del(){
  ShowConfirm();
  //请问在这里怎么判断ShowConfirm()之后,用户点的是什么,才能往下执行???如果用户点击取消,只隐藏divConfrim就行了,如果是确定那么就往下执行。
  alert("往下执行的代码!");//这里是一定要等用户点确定后才能执行的代码
}
</script>
<input type="button" value="删除" onclick="Del()">

解决方案 »

  1.   

    不清楚楼主问什么,等一下再看~~~<html>
    <body>
    <script>
    var bool=confirm("继续吗?")
    alert(bool)
    </script>
    </body>
    </html>
      

  2.   

    这其实是一个自定义的一个confrim的对话框。像实现window.confirm的功能
      

  3.   

    <script>
    function ShowConfirm(){
    oDiv = document.createElement("div");
    oDiv.id = "divConfirm";
    oDiv.style.cssText="display:none;z-index:99;position:absolute;left:200;top:200;width:100%;height:"+document.body.scrollHeight+";";
    str = "<input type='button' value='确定' onClick=\"confirm(true);\">";
    str += "<input type='button' value='取消' onClick=\"confirm(false);\">";oDiv.innerHTML = str;
    document.body.appendChild(oDiv);
    oDiv.style.display='';
    }function confirm(bool){
    document.getElementById('divConfirm').style.display='none';
    if(bool){
    alert("往下执行的代码!");
    }}
    function Del(){
    ShowConfirm();
    //请问在这里怎么判断ShowConfirm()之后,用户点的是什么,才能往下执行???如果用户点击取消,只隐藏divConfrim就行了,如果是确定那么就往下执行。//这里是一定要等用户点确定后才能执行的代码
    }
    </script>
    <input type="button" value="删除" onclick="Del()">
      

  4.   

    <script>
    function ShowConfirm(){
      oDiv = document.createElement("div");
      oDiv.id = "divConfirm";
      oDiv.style.cssText="display:none;z-index:99;position:absolute;left:200;top:200;width:100%;height:"+document.body.scrollHeight+";";
      str = "<input type='button' value='确定' id='yes'/>";
      str += "<input type='button' value='取消' id='no'/>";  oDiv.innerHTML = str;
      document.body.appendChild(oDiv);
    oDiv.style.display='';
    }
    function Del(){
      ShowConfirm();
      var yes=document.getElementById("yes");
      yes.onclick=yestodo;
      var no=document.getElementById("no");
      no.onclick=notodo;
    }
    function yestodo(){}
    function notodo(){}
    </script>
    <input type="button" value="删除" onclick="Del()">
      

  5.   

    前面两位的,还是不行,肯定是我没有表达清楚..
    实际上代码是这样的,
    //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("往下执行的代码!");//这里是一定要等用户点确定后才能执行的代码
    }
    到底应该怎么做呢????????????????????????????
      

  6.   

    function Del(){
    ShowConfirm();
    //请问在这里怎么判断ShowConfirm()之后,用户点的是什么,才能往下执行???如果用户点击取消,只隐藏divConfrim就行了,如果是确定那么就往下执行。
    alert("往下执行的代码!");//这里是一定要等用户点确定后才能执行的代码
    }
    showconfirm()
    显示之后,不会等用户输入
    它的任务只是显示面板
    alert("往下执行的代码!");
    必须放在另一个方法中
    在面板的[确定/取消]选择后再判断是否执行
    我敢说你并没有运行我写的示例
      

  7.   

    那这个效果不是很难做出来,这就是想调用这个函数里,弹出一个DIV 来,用户点确定后返回true,否则返回false,这只是一个模块。如果往下执行的代码要放在另一个函数中,那不是太麻烦了。因为有好多要调用这个功能的函数
      

  8.   

    如果一定要在一个方法中处理
    可以如下<script>
    function ShowConfirm(){
    oDiv = document.createElement("div");
    oDiv.id = "divConfirm";
    oDiv.style.cssText="display:none;z-index:99;position:absolute;left:200;top:200;width:100%;height:"+document.body.scrollHeight+";";
    str = "<input type='button' value='确定' onClick=\"Del(true);\">";
    str += "<input type='button' value='取消' onClick=\"Del(false);\">";oDiv.innerHTML = str;
    document.body.appendChild(oDiv);
    oDiv.style.display='';
    }
    function Del(bool){
     if(bool == null){
    //没有传入参数,显示面板
    ShowConfirm();
    }
    else{ 
    //隐藏面板
    document.getElementById('divConfirm').style.display='none';
    if(bool){
       alert("选择了确定,继续");
     }
     else{
    alert("选择了取消.中止");
     }
     }
    }
    </script>
    <input type="button" value="删除" onclick="Del()">
      

  9.   

    首先,感谢你的回答!这个方法确实可以,但是还是有一个美中不足的地方。问一下,如果我每调用这个自定义的confrim,那么,我就要把调用它的函数名称给传进去吗??例,如果我下一个调用它的方法名为Modify,那么,这个函数的onClick=\"Del(true);是不是没有效了呢???
     
      

  10.   

    其实他已经解决了这个问题,至于是不是每次要传函数名,好像可以考虑用Prototype之类的东西来封装一下,这属于代码重构了。
      

  11.   

    怎么用Prototype来封装,请高手详解!!