<html>
<body>
<span id="tspan"></span>
<script language=javascript>
var i=0;
function t()
{
document.getElementById('tspan').innerText = ++i;
}
window.setInterval('t()',500);
</script>
<input type=button value=click onclick="alert('Stoped?');" />
</body>
</html>可以用这个页面来演示问题,如果不弹出alert对话框,计时程序正常运行,一弹出,setInterval就被阻塞了!!请问该如何避免!!

解决方案 »

  1.   

    这个不能实现,不过你可以动态create一个div来模拟alert弹出框。
      

  2.   

    谢谢CutBug,问题是现在是在一个已经完成的项目上加上了这么个计数程序,如果要改成弹出DIV的话,那要改好多的地方,如果能找到一种解决方法,相信对所有写JS的朋友们都有帮助的!
      

  3.   

    通过 一些事件来触发可以构造出另外一个线程,例如:image 的 onload,xmlhttp 的 onreadystatechange, 等等。
      

  4.   

    请问wuyan_xjb() ,这个方式我也想过,但不知该如何具体实现,能否给点思路,谢谢!!
      

  5.   

    这个可以,自己修改下
    <body>
    <style>
    div{
    width:100;
    border:solid 2px #999;
    margin:2 2 2 2;
    display:inline;
    }
    span{
    height:100%;
    width:50;
    float:right;
    }
    marquee{
    width:1;
    height:100%;
    float:left
    }
    </style><input type="button" value="点击自动新开" onclick="doAuto(this)">
    <script>
    function doAuto(oBtn){
    oBtn.disabled = true;
    document.body.insertAdjacentHTML("beforeend","<marquee  SCROLLDELAY='500' onscroll='addNew()'>&nbsp;&nbsp; &nbsp; </marquee>");
    alert("每秒开2个~~ :) \n对话框没有让脚本停止运行\n它还在继续跑 :) ");
    }
    function addNew(){
    var marquee = document.createElement("<marquee  SCROLLDELAY='100' onclick='alert(0)'></marquee>");
    marquee.innerHTML = "&nbsp;&nbsp;";
    var oCounter=  document.createElement("span");
    var Parent = document.createElement("div");
    var Counter = 1;
    Parent.appendChild(marquee);
    Parent.appendChild(oCounter);
    document.body.appendChild(Parent);
    marquee.onscroll=function(){
    oCounter.innerHTML = ++Counter;
    }
    }
    </script>
    </body>
    来自:http://bbs.51js.com/viewthread.php?tid=63523
      

  6.   

    我这里倒是有个变通的方法:
    <html>
    <head>
    <script language=javascript>
    var i=0;
    function t()
    {
    document.getElementById('tspan').innerText = ++i;
    }
    window.setInterval('t()',500);
    </script><script language=vbscript>
    sub stopped()
    set OpenWindow1=window.open("", "newwin", "height=1, width=1,toolbar=no,scrollbars=no,menubar=no")
    OpenWindow1.document.write("<TITLE>例子</TITLE>") 
    OpenWindow1.document.write(chr(60) & "script language=javascript" & chr(62)) 
    OpenWindow1.document.write("alert(" & chr(39) & "Stoped?" & chr(39) & ");") 
    OpenWindow1.document.write("window.close()")
    OpenWindow1.document.write(chr(60) & "/script" & chr(62))
    end sub
    </script>
    </head>
    <body>
    <span id="tspan"></span>
    <input type=button value=click  onclick="stopped()">
    </body>
    </html>你可以产生另外一个窗体,设置显示位置看不见,然后弹出对话框。
    也有缺陷:比如在我这里对脚本安全性要求高,因此每次使用script语句,ie上都有显示“为帮助保护您的安全,……”,必须选择“允许阻止的内容”才让运行脚本,因此在弹出的窗口上也有这个问题。
      

  7.   

    我也做了一个,你贴上试试。
    <html>
    <body>
    <span id="tspan"></span>
    <style>
    .show
    {
     display:block;
     width:150px;
     height:150px;
     background:gray;
    margin-left:300px;
    margin-top:150px;}
    .btn
    {
    margin-top: 120px;}
    .hid
    {
    display:none;
    }
    </style><script language=javascript>
    var i=0;
    function t()
    {
    document.getElementById('tspan').innerText = ++i;
    }
    window.setInterval('t()',500);function show_alert()
    { document.getElementById("alert_me").className  = "show";
    }function del_alert()
    { document.getElementById("alert_me").className  = "hid";
    }
    </script>
    <input type=button value=click onclick="show_alert();" />
    <div  id="alert_me"  class ="hid"> 
    <span id = "prompt"></span>
      <center><input name="button"  class = "btn"type = "button" id="btn" onClick="del_alert();" value="确定"/></center>
    </div>
    </body>
    </html>