CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Web 开发 >  JavaScript

数组中的SORT()是按什么原则排序的呢?

楼主langhun1984(浪魂)2006-03-04 11:04:26 在 Web 开发 / JavaScript 提问

?? 问题点数:10、回复次数:5Top

1 楼net_lover(【孟子E章】)回复于 2006-03-04 11:08:08 得分 0

the   elements   are   sorted   in   ascending,   ASCII   character   order.    
  Top

2 楼net_lover(【孟子E章】)回复于 2006-03-04 11:11:27 得分 0

可参考  
  http://blog.iyi.cn/hily/archives/2005/10/javascriptsort.html  
  Top

3 楼KimSoft(革命的小酒天天醉-http://blog.csdn.net/kimsoft/)回复于 2006-03-04 15:05:18 得分 0

 
  <SCRIPT   LANGUAGE="JavaScript">  
  <!--  
  //默认按字符编码顺序。不过可以改变一下。  
  var   ary   =   new   Array(10,   12,   32,   53,   67,   88,   35,   111,   222,   23,   96,   37,   43)  
   
  document.writeln   (ary.sort().join())                           //按字符编码  
  document.writeln   ("<br>")  
  document.writeln   (ary.sort(mumberOrder).join())     //按数字大小,可更改成return   a   -   b  
   
  function   mumberOrder(a,   b){  
      return   b   -   a;  
  }  
  //-->  
  </SCRIPT>  
  Top

4 楼iuhxq(小灰)回复于 2006-03-04 15:17:20 得分 0

<title>WEB文件管理器2.0版   http://asp2004.net</title>  
  <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">  
  <style   type="text/css">  
  <!--  
  a   {  
    font-size:   9pt;  
    color:   #3300CC;  
    text-decoration:   none;  
  }  
  body   {  
    font-size:   9pt;  
    margin-left:   0px;  
    margin-top:   0px;  
    margin-right:   0px;  
    margin-bottom:   0px;  
    line-height:   20px;  
    background-color:   #EEEEEE;  
  }  
  td   {  
    font-size:   9pt;  
    line-height:   20px;  
  }  
  .tx   {  
    border-color:#000000;  
    border-left-width:   0px;  
    border-top-width:   0px;  
    border-right-width:   0px;  
    border-bottom-width:   1px;  
    font-size:   9pt;  
    background-color:   #EEEEEE;  
  }  
  .tx1   {  
    font-size:   9pt;  
    border:   1px   solid;  
    border-color:#000000;  
    color:   #000000;  
  }  
  -->  
  </style>  
  <%  
   
  '版权声明:本代码仅供学习研究之用,本人不对因使用本程序而造成的任何后果负责。未经作者书面许可不得用于商业用途。  
  'QQ:103895  
  'email:quxiaohui_0@163.com  
  'http://asp2004.net  
   
  Server.ScriptTimeout   =   999  
  action   =   Request("action")  
  temp   =   Split(Request.ServerVariables("URL"),   "/")  
  url   =   temp(UBound(temp))  
   
  Const   pass   =   ""'登陆密码  
   
  '登陆验证  
   
  Set   fso   =   CreateObject("Scripting.FileSystemObject")  
                  Path   =   Request("foldername")  
                  If   Path   =   ""   Then   Path   =   server.MapPath("./")  
                  ShowFolderList(Path)  
  Set   fso   =   Nothing  
   
  '列出文件和文件夹  
   
  Function   ShowFolderList(folderspec)  
          temp   =   Request.ServerVariables("HTTP_REFERER")  
          temp   =   Left(temp,   Instrrev(temp,   "/"))  
          temp1   =   Len(folderspec)   -   Len(server.MapPath("./"))   -1  
          If   temp1>0   Then  
                  temp1   =   Right(folderspec,   CInt(temp1))   +   "\"  
          ElseIf   temp1   =   -1   Then  
                  temp1   =   ""  
          End   If  
          tempurl   =   temp   +   Replace(temp1,   "\",   "/")  
          uppath   =   "./"   +   Replace(temp1,   "\",   "/")  
          upfolderspec   =   fso.GetParentFolderName(folderspec&"\")  
          Set   f   =   fso.GetFolder(folderspec)  
  %>  
  <script   language="javascript">  
  function   File(Name,   Size,   Type,   DateCreated,   DateLastAccessed,   DateLastModified,   Attributes)  
  {  
    this.Name   =   Name;  
    this.Size   =   Size;  
    this.Type   =   Type;  
    this.DateCreated   =   DateCreated;  
    this.DateLastAccessed   =   DateLastAccessed;  
    this.DateLastModified   =   DateLastModified;  
    this.Attributes   =   Attributes;  
  }  
   
  function   Tree(id,   name)  
  {  
    this.id   =   id;  
    this.name   =   name;  
    this.root   =   new   Array();  
    this.length   =   0;  
     
    this.Add   =   function(file)  
    {  
      this.root.push(file);  
      this.length   +=   1;  
    }  
    this.max   =   function(f1,   f2,   field)  
    {  
      switch(   field   )  
      {  
        case   "Name":  
          return   f1.Name.toLowerCase()>f2.Name.toLowerCase()?   true:false;  
        case   "Size":  
          return   f1.Size>f2.Size?   true:false;  
        case   "Type":  
          //if   (field   ==   '???t?D')   return   false;  
          return   f1.Type>f2.Type?   true:false;  
        case   "DateCreated":  
          return   f1.DateCreated>f2.DateCreated?   true:false;  
        case   "DateLastAccessed":  
          return   f1.DateLastAccessed>f2.DateLastAccessed?   true:false;  
        case   "DateLastModified":  
          return   f1.DateLastModified>f2.DateLastModified?   true:false;  
        case   "Attributes":  
          return   f1.Attributes>f2.Attributes?   true:false;  
        default:  
          return   false;  
      }  
    }  
    this.sort=function(field,   order)  
    {  
    //order:desc   asc  
    //field:Name   Size  
      var   len   =   this.root.length;  
      if(   len   <   2   )   return;  
      var   tmp;  
      for(var   i=0;   i<len-1;   i++)  
      {  
        for(var   j=i+1;   j<len;   j++)  
        {  
          if(   order   ==   "desc")  
          {  
            if(   !this.max(   this.root[i],   this.root[j],   field   )   )  
            {  
              tmp   =   this.root[i];  
              this.root[i]   =   this.root[j];  
              this.root[j]   =   tmp;  
            }  
          }  
          else   if   (   order   ==   "asc")  
          {  
            if(   this.max(   this.root[i],   this.root[j],   field   )   )  
            {  
              tmp   =   this.root[i];  
              this.root[i]   =   this.root[j];  
              this.root[j]   =   tmp;  
            }  
          }  
        }  
      }  
    }  
  }  
  function   fieldcode(field)  
  {  
    if   (order   ==   'desc')  
    {  
      order   =   'asc';  
    }  
    else  
    {  
      order   =   'desc';  
    }  
    tree.sort(field,   order);  
  }  
  function   show()  
  {  
  //for   (var   i=0;i<form1.elements.length;i++){var   e   =   form1.elements[i];if   (e.type   ==   "checkbox")e.checked   =   form1.chkall.checked;}  
    str   =   '<table   width="100%"   border="0"   cellspacing="0"   cellpadding="0">\  
      <tr   bgcolor="#EEEEEE">\  
      <td><div   align="center">操作<input   type="checkbox"   name="chkall"   onclick=""></div></td>\  
      <td><div   align="center"><a   onclick="fieldcode(\'Name\');show();"   href=#>文件名</a></div></td>\  
      <td><div   align="center"><a   onclick="fieldcode(\'Size\');show();"   href=#>大小</a></div></td>\  
      <td><div   align="center"><a   onclick="fieldcode(\'Type\');show();"   href=#>类型</a></div></td>\  
      <td><div   align="center"><a   onclick="fieldcode(\'DateCreated\');show();"   href=#>创建时间</a></div></td>\  
      <td><div   align="center"><a   onclick="fieldcode(\'DateLastAccessed\');show();"   href=#>上次访问时间</a></div></td>\  
      <td><div   align="center"><a   onclick="fieldcode(\'DateLastModified\');show();"   href=#>上次修改时间</a></div></td>\  
      <td><div   align="center"><a   onclick="fieldcode(\'Attributes\');show();"   href=#>属性</a></div></td>\  
      </tr>';  
    var   f;  
    for(i=0;i<tree.length;i++)  
    {  
      f   =   tree.root[i];  
      str   +=   '<tr   bgcolor="#EEEEEE"   onmouseover=this.bgColor=\'#F3F6FA\';   onmouseout=this.bgColor=\'#EEEEEE\';>\  
        <td><center><input   type="checkbox"   name="f"   value="'+tree.id+"\\\\"+f.Name+'"></center></td>\  
        <td><a   href="'+f.url+'">'+f.Name+'</a></td>\  
        <td>'+f.Size+'</td>\  
        <td>'+f.Type+'</td>\  
        <td>'+f.DateCreated+'</td>\  
        <td>'+f.DateLastAccessed+'</td>\  
        <td>'+f.DateLastModified+'</td>\  
        <td>'+f.Attributes+'</td>\  
        </tr>';  
    }  
    str   +=   '</table>';  
    eval(list).innerHTML   =   str;  
  }  
  var   field   =   'Name';  
  var   order   =   'desc';  
  var   str;  
  </script>  
  <body   onLoad="show()">  
  <form   name="form1"   method=post   action="">  
  <span   id="list"></span>  
  </form>  
  </body>  
  <%  
   
  Response.Write("<script   language=javascript>"&vbcrlf)  
  Response.Write("var   tree   =   new   Tree('"&jscode(f.path)&"','"&jscode(f.name)&"');"&vbcrlf)  
  Set   fc   =   f.SubFolders  
  For   Each   f1   in   fc  
    Response.Write("tree.Add(new   File('"&f1.name&"',"&f1.size&",'"&f1.Type&"','"&f1.DateCreated&"','"&f1.DateLastAccessed&"','"&f1.DateLastModified&"','"&f1.Attributes&"'));"&vbcrlf)  
  Next  
  set   fc   =   f.Files  
  For   Each   f1   in   Fc  
    Response.Write("tree.Add(new   File('"&f1.name&"',"&f1.size&",'"&f1.Type&"','"&f1.DateCreated&"','"&f1.DateLastAccessed&"','"&f1.DateLastModified&"','"&f1.Attributes&"'));"&vbcrlf)  
  Next  
  Response.Write("</script>")  
  End   Function  
   
  function   jscode(s)  
    jscode   =   replace(s,"\","\\\\")  
  end   function  
   
  %>  
  Top

5 楼liu76xt((网事随逢))回复于 2006-06-29 09:56:04 得分 0

都是高高手啊。Top

相关问题

  • 数组排序
  • 数组排序?
  • 数组排序?
  • ◆数组排序
  • 数组排序----急
  • 怎样用JavaScript数组的sort方法对中文字符串数组排序?
  • 怎么使用数组的sort()方法进行排序???
  • 数组长度和数组排序
  • ------------------------数组排序问题?-----------------------------------
  • 数组排序的问题........

关键词

  • folderspec
  • temp1
  • sorted
  • fso
  • replace
  • then

得分解答快速导航

  • 帖主:langhun1984

相关链接

  • Web开发类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo