<input name="S1" type="button" id="S1" value="1" onClick="Warn(this)">

解决方案 »

  1.   

    改为:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <script language="JavaScript">
     function Warn(){
      if(document.all('S1').style.background=="#ffffff")
        document.all('S1').style.background="#ffff00";
      else
       document.all('S1').style.background="#ffffff";
       setTimeout("Warn()", 200);
     }
    </script>
    </head><body>
    <input name="S1" type="button" id="S1" value="1" onClick="Warn()">
    <input name="S12" type="button" id="S12" value="2">
    </body>
    </html>
    即可
      

  2.   

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <script language="JavaScript">
     function Warn(obj)
     {
       var bg = obj.style.backgroundColor;
       obj.style.backgroundColor = (bg!="#ffffff") ? "#ffffff" : "#ffff00";
       setTimeout("Warn(document.all."+ obj.id +")", 200);
     }
    </script>
    </head><body>
    <input name="S1" type="button" id="S1" value="1" onClick="Warn(this)">
    <input name="S12" type="button" id="S12" value="2">
    </body>
    </html>
      

  3.   

    问题出在setTimeout中的参数传递上了 -_-
    <script language="JavaScript">
    var tmpObj;
     function Warn(obj){
      tmpObj=obj;
      if(obj.style.background=="#ffffff")
        obj.style.background="#ffff00";
      else
       obj.style.background="#ffffff";
       setTimeout("Warn(tmpObj)", 200);
     }
    </script>
    <input name="S1" type="button" id="S1" value="1" onClick="Warn(this)">
    <input name="S12" type="button" id="S12" value="2">
      

  4.   

    其实这样就可以了:
    <input name="S1" type="button" id="S1" value="1" onClick="setInterval('S1.style.background=(S1.style.background==\'white\'?\'yellow\':\'white\')',200)">
      

  5.   

    关键不是 Warn(this)的问题 主要问题是梅花大哥说的  obj.style.backgroundColor  这样才对document.all('S1').style.background  这样的方式也能解决 但是不灵活!