反转输出字符串的顺序?

时间:2014-05-27 18:05:00

标签: javascript jquery string timestamp

我有一个代码可以创建一个文本框,点击提交按钮后,它会打印出#34;用户在文本框前面输入一个日期戳,然后在单击提交后提交更多输入(它将在第一个打印输入下打印新输入,依此类推);我希望输出按时间排序(即最新的帖子应该在页面的顶部)。

     <!DOCTYPE HTML>
<HTML>
<head>
<link rel="stylesheet" type="text/css" href="css.css">
</head>
<font size="5">
 <body background="images/blbkgnd.gif" bgcolor="#FFFFFF" text="#000000" link="#999999" vlink="#990000" alink="#666666"> 
 <table id="table" width="700">
 <tr>
 <td> </td>
 </tr>
 <br>
 <textarea id="txtInput" style="width: 50em; height: 15em;"></textarea>
 <input type="button" id="btn" value="Submit"> 

 <script> 
 function enter() { 
     var txtInput = document.getElementById("txtInput");
     var output=document.getElementById("table").rows[0].cells;
     var m = new Date();
     var month = new Array();
 month[0] = "January";
 month[1] = "February";
 month[2] = "March";
 month[3] = "April";
 month[4] = "May";
 month[5] = "June";
 month[6] = "July";
 month[7] = "August";
 month[8] = "September";
 month[9] = "October";
 month[10] = "November";
 month[11] = "December";
     var monthName=month[m.getMonth()];
     var date=m.getUTCDate();
     var year= m.getUTCFullYear();

        output[0].innerHTML+="<br>"+"<br>"+"<br>"+date+" "+monthName+" "+year+"<br>"+txtInput.value+"\n";
 } 

 document.getElementById("btn").onclick = enter; 
 </script> 
 </font>
 </HTML>

1 个答案:

答案 0 :(得分:0)

output[0].innerHTML = date+" "
                      +monthName+" "+year+"<br>"
                      +txtInput.value
                      +"<br>"+"<br>"+"<br>"+"\n" 
                      + output[0].innerHTML;