我想使用逗号分隔列表
排序表var list = 15,11,16,17,18,19,20,21,22,29,30,31,34,38,39,40;
我的html表
<tr id="recordsArray_11"><td>11</td></tr>
<tr id="recordsArray_15"><td>15</td></tr>
<tr id="recordsArray_16"><td>16</td></tr>
如何在此列表中显示订单?
答案 0 :(得分:0)
var list = 15,11,16,17,18,19,20,21,22,29,30,31,34,38,39,40;
因为此时列表只是一系列数字,所以它仍然是文本,因此在声明时用单引号或双引号括起来。
只能声明一个数字var:var interest_rate = 0.025;
var list = "15,11,16,17,18,19,20,21,22,29,30,31,34,38,39,40";
list = list.split(","); // list is become list[]
list.sort() //now sorted
var table=document.getElementById("my-table-name");
for(i=0,i<list.length;i++){
var tr=document.createElement("tr");
var td=document.createElement("td");
tr.id="recordsArray_"+list[i];
td.value=list[i];
tr.appendChild(td);
table.appendChild(tr);
}