看不出是什么问题,我是这样写的:function checkOS () {
//转换成小写以方便运算
var userAgent = navigator.userAgent.toLowerCase();
var osStr = ""; this.win31 = (userAgent.indexOf("windows 3.1")!=-1) || (userAgent.indexOf("win16")!=-1) || (userAgent.indexOf("windows 16-bit")!=-1);
osStr = (this.win31) ? osStr+"win31" : osStr+"";
this.win95 = (userAgent.indexOf("win95")!=-1) || (userAgent.indexOf("windows 95")!=-1);
osStr = (this.win95) ? osStr+"win95" : osStr+"";
this.win98 = (userAgent.indexOf("win98")!=-1) || (userAgent.indexOf("windows 98")!=-1);
osStr = (this.win98) ? osStr+"win98" : osStr+"";
this.winNT = ((userAgent.indexOf("winnt")!=-1) || (userAgent.indexOf("windows nt")!=-1)) && (userAgent.indexOf("windows nt 5.0")==-1);
osStr = (this.winNT) ? osStr+"winNT" : osStr+"";
this.win2000 = userAgent.indexOf("windows nt 5.0") != -1;
osStr = (this.win2000) ? osStr+"win2000" : osStr+"";
this.winME = userAgent.indexOf("win 9x 4.90") != -1;
osStr = (this.winME) ? osStr+"winME" : osStr+"";
this.winXP = userAgent.indexOf("windows nt 5.1") != -1;
osStr = (this.winXP) ? osStr+"winXP" : osStr+""; this.os2 = (userAgent.indexOf("os/2")!=-1) || (userAgent.indexOf("ibm-webexplorer")!=-1) || (navigator.appVersion.indexOf("OS/2")!=-1);
osStr = (this.os2) ? osStr+"os" : osStr+""; this.mac = userAgent.indexOf("mac") != -1;
osStr = (this.mac) ? osStr+"mac" : osStr+""; this.linux = userAgent.indexOf("linux") != -1;
osStr = (this.linux) ? osStr+"linux" : osStr+""; this.osStr = osStr;
}
var clientOS = new checkOS();
document.write("您的操作系统是:" + clientOS.osStr);

解决方案 »

  1.   

    var mxh=new Is();
      for(i in mxh)
           {
             if(mxh[i]==0)
                    continue;
             else
                  {
                     for (var j=0;j<os.length;j++){
                       if(mxh[i]==j)
                         document.write("您的操作系统:" + os[j] + "<br>");
                     }              }
           }
      

  2.   

    danky()我原来写的也类似你写的那个但是输出的是win95,win95...而我要的“windows 95”“windows 98”这种的,最烦的是中间的空格!! Laone(Laone) 的方法我也用过了,不成功!所以才来这问的!
      

  3.   

    <script>
    function Is()
    {  var agt=navigator.userAgent.toLowerCase();  // *** 使用平台检测 ***
      this.win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1)) ? 1 : 0 ;
      this.win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1)) ? 2 : 0 ;
      this.winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt 4.0")!=-1)) ? 3: 0 ;
      this.winme = ((agt.indexOf("win 9x 4.90")!=-1)) ? 4 : 0 ;
      this.win2k = ((agt.indexOf("windows nt 5.0")!=-1)) ? 5 : 0 ;
      this.winxp = ((agt.indexOf("windows nt 5.1")!=-1)) ? 6 : 0 ;
      this.os2   = ((agt.indexOf("os/2")!=-1) ||
                      (navigator.appVersion.indexOf("OS/2")!=-1) ||
                      (agt.indexOf("ibm-webexplorer")!=-1)) ? 7 : 0 ;  this.mac    = (agt.indexOf("mac")!=-1) ? 8 : 0 ;  if (this.mac && this.ie5up) this.js = 1.4;
      this.mac68k = (this.mac && ((agt.indexOf("68k")!=-1) ||
                                 (agt.indexOf("68000")!=-1))) ? 9 : 0 ;
      this.macppc = (this.mac && ((agt.indexOf("ppc")!=-1) ||
                                  (agt.indexOf("powerpc")!=-1))) ? 10 : 0 ;  
    }
      var os=new Array(10);  os[1]="Windows 95"
      os[2]="Windows 98"
      os[3]="Windows NT"
      os[4]="Windows ME"
      os[5]="Windows 2000"
      os[6]="Windows XP"
      os[7]="os2"
      os[8]="mac"
      os[9]="mac68k"  var mxh=new Is();
      var j=1;
      for(i in mxh)
           {
             if(mxh[i]!=0) document.write("您的操作系统:" + os[j] + "<br>");
     j++;
           }
    </script>
      

  4.   

    你的问题,j没有定义,跟i混淆了,i是mxh的属性。
      

  5.   

    修改了一下你的代码,应该用起来会更方便点。<script>
    function Is()
    {  var agt=navigator.userAgent.toLowerCase();  // *** 使用平台检测 ***
      this.win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1)) ? 1 : 0 ;
      this.win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1)) ? 2 : 0 ;
      this.winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt 4.0")!=-1)) ? 3: 0 ;
      this.winme = ((agt.indexOf("win 9x 4.90")!=-1)) ? 4 : 0 ;
      this.win2k = ((agt.indexOf("windows nt 5.0")!=-1)) ? 5 : 0 ;
      this.winxp = ((agt.indexOf("windows nt 5.1")!=-1)) ? 6 : 0 ;
      this.os2   = ((agt.indexOf("os/2")!=-1) ||
                      (navigator.appVersion.indexOf("OS/2")!=-1) ||
                      (agt.indexOf("ibm-webexplorer")!=-1)) ? 7 : 0 ;  this.mac    = (agt.indexOf("mac")!=-1) ? 8 : 0 ;  if (this.mac && this.ie5up) this.js = 1.4;
      this.mac68k = (this.mac && ((agt.indexOf("68k")!=-1) ||
                                 (agt.indexOf("68000")!=-1))) ? 9 : 0 ;
      this.macppc = (this.mac && ((agt.indexOf("ppc")!=-1) ||
                                  (agt.indexOf("powerpc")!=-1))) ? 10 : 0 ;
      this.platform=0;  var os=new Array(10);  os[1]="Windows 95"
      os[2]="Windows 98"
      os[3]="Windows NT"
      os[4]="Windows ME"
      os[5]="Windows 2000"
      os[6]="Windows XP"
      os[7]="os2"
      os[8]="mac"
      os[9]="mac68k"  var j=1;
      for(obj in this)
        {
     if(this[obj]!=0) 
    {
     this.platform=os[j];
     break;
     }
     j++;
    }
    }
      var mxh=new Is();
      alert(mxh.platform);
    </script>