一个javascript问题求助,其实我想实现的功能是用层来代替浏览器弹出的窗口,例如alert()等,但当我弹出层的时候,层函数下面的代码继续执行,有什么办法可以象alert()一样,当执行alert()后,如果不点确定alert()后面的代码就不执行呢?大家帮下忙。例如:
alert();
xxx;
xxx;
alert()下的xxxx是不会执行。而我自定义的层:
showBox();//假设这个函数可以显示和alert()一样内容的层,带有一个确定按键。
xxxxx;
xxxxxx;
showBox()下面的xxxx代码执行了,我想等待点层的确定后再运行xxxx;

解决方案 »

  1.   

    function showBox()
    {
    if(window.confirm("确认退出?"))
    {
    XXXXXXXXXXXX;
    XXXXXXXXX
    }
    }
      

  2.   


    首先多谢你的回答,但你没了解我要的功能。我要的是用层来模仿alert(),confirm()等功能。
      

  3.   

    层是覆盖了,可下面的js代码还会继续走下去吧。用settimeout模拟java中的线程阻塞,直到调用层的函数返回一个结果为止。
      

  4.   

    就像51job上那种弹出一样的吧,像4楼说的,用覆盖来做//General
    var W=screen.width;
    var H=screen.height;
    //Get document
    function get(id){
    return document.getElementById(id);
    }
    //Create document
    function create(t){
    return document.createElement(t);
    }
    //Validate is IE
    function isIE(){
       return (document.all&&window.ActiveXObject&&!window.opera)?true:false;
    }
    //Get Page width
    function getBodySize(){
       var bodySize=[];
       with(document.documentElement){
    bodySize[0]=(scrollWidth>clientWidth)?scrollWidth:clientWidth;
    bodySize[1]=(scrollHeight>clientHeight)?scrollHeight:clientHeight;
       }
       return bodySize;
    }
    //Cover window
    function popCover(){
    if(get("cover_div")){
    get("cover_div").style.display='block';
    }else{
    var coverDiv=create('div');
    document.body.appendChild(coverDiv);
    coverDiv.id='cover_div';
    with(coverDiv.style){
    position='absolute';
    background = '#CCCCCC';
    left='0px';
    top='0px';
    var bodySize=getBodySize();
    width=bodySize[0]+'px';
    height=bodySize[1]+'px';
    zIndex=0;
    if(isIE()){
    filter="Alpha(Opacity=60)";
    }else{
    opacity=0.6;
    }
    }
    }

    }//Show country
    //Get country information
    function getCountry(){
    var url="getcountry.action";
    var parame;
    jQuery.post(url,parame,function(data){
    changeDiv_country();//Change country div;
    showDiv_country(data);//show country div;
    popCover();//block body div;
    }, 'json');
    }
    //Set country div information
    function showDiv_country(data){
      var countrydiv=get("countrydiv");
      //Get result country
      var str="";
      str+="<a href='javascript:closeCountry()'>close<a><br>";
      if(data.countrylist==null){
      str+="Cannot get countrylist";
      }
      var i=1;
      for(var key in data.countrylist){
      var id=key.toString();
      var name=data.countrylist[id];
      str+="<td>";
      str+="<a href=\"javascript:setCountry("+id+",'"+name+"')\">"+name+"</a>";
      if(i%3==0){
      str+="<br>";
      }
      i++;
    }
    str+="</td>";
    str+="<br>";
      countrydiv.innerHTML=str;
      countrydiv.style.display="block";
    }
    //Set div style
    function changeDiv_country(){
    var countrydiv=get("countrydiv");
    countrydiv.style.position="absolute";
    countrydiv.style.border = "1px solid #CCCCCC";
    countrydiv.style.background ="#F6F6F6";
    var i=10;
    var bodySize=getBodySize();
    countrydiv.style.left=(bodySize[0]-i*i*4)/2+"px";
    countrydiv.style.top=(bodySize[1]/2-100-i*i)+"px";
    countrydiv.style.width=i*i*4 + "px";
    countrydiv.style.height=i*i*1.5+ "px";
    }//Set value for hidden input
    function setCountry(id,name){
    get('10').value=name;
    get('country_value').value=id;
    get('11').value="";//Set state null
    get('state_value').value="";
    closeCountry();
    }//Clost country pop window
    function closeCountry(){
    get('countrydiv').style.display='none';
    get('cover_div').style.display='none';
    }
    这是我很早以前做的一个,现在不用了,楼主可以试试,应该可以用的 
      

  5.   

    能不能给showbox一个返回值呢?