zoukankan      html  css  js  c++  java
  • 使用prompt输入一句英文句子和排序方式(升/降),将所有单词按排序方式排序后在网页上输出

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
    <script language="JavaScript" type="text/javascript"> 
     
            function addnew() 
            { 
                  c   =   prompt("请输入内容!","");//
                  way   =   prompt("请输入排序方式(升 1/降 0)!","");//
                  if   (c   ==   null)    
                  {    
                      return false;  
                  }    
                  else   if   (c.replace(/^s+|s+$/g,"")   ==   "")    
                  { 
                    alert("输入内容为空!");    
                     return false; 
                  } 
                //  alert(c); 
                 // alert(way); 
            } 
            addnew(); 
            var arr1 = c.toString().split(" "); 
            if(way==1) 
            { 
                arr1.sort(); 
                for(var i=0;i<arr1.length;i++) 
                    document.write(arr1[i]+"   "); 
            } 
            //(降序) 
            else 
            { 
                arr1.sort(function (a,b){return a>b?-1:1}); 
                for(var i=0;i<arr1.length;i++) 
                    document.write(arr1[i]+"   "); 
            } 
     
    </script> 
    </body> 
     
     
    <title>无标题文档</title> 
    </head> 
     
    <body> 
    </body> 
    </html> 

    本文出自 “阿凡达” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/812996

  • 相关阅读:
    质因数分解
    P1939 【模板】矩阵加速(数列)
    UVALive
    Python操作MySQL:pymysql模块
    Mysql数据库基础
    Redis管道和发布订阅
    Redis常用操作
    Redis操作集合,有序集合
    Redis操作list
    Redis操作hash
  • 原文地址:https://www.cnblogs.com/umgsai/p/3908203.html
Copyright © 2011-2022 走看看