<html>
<head>
<title></title>
</head>
<body>
<input type="button" onclick="window.setTimeout('var aa="ww";alert(aa)', 1, 'javascript')"
value="dd"></input>
</body>
</html>
上面定义aa是有错误的,请问该如何写才是正确的。
谢谢各位大哥帮忙!

解决方案 »

  1.   

    看样子你好象要提供点击按纽后调用一个循环定时器来做些什么事情,我建议把代码写开,不要集中到一行去,可以先写出你要调用的方法,再把它连到onclick事件里面去.而且我用循环定时器时一般使用两个参数,1,时间2,函数名.
      

  2.   

    <html>
    <head>
    <title></title>
    </head>
    <body>
    <input type="button" onclick="window.setTimeout(function(){var aa='ww';alert(aa);}, 1000, 'javascript');" value="dd"></input>
    </body>
    </html>
      

  3.   

    <script type="text/javascript">
    function aa(){
      var aa="1";
      alert(aa);
      setTimeout("aa()",1);//这中循环,最好做一个跳出条件,否则很麻烦的
    }
    </script>
    <input type="button" onclick="aa()" value="ddd"/>
      

  4.   

    顶。.关于这些代码太多而且有逻辑的 
    应该写在function 中
    那就不需要理会转义字符了
    function cTmpCodeOnload( type)
    {  
    alert(type)
    setTimeout("cTmpCodeOnload("+type+")",5000) 
    }