我制作了一个数组,用于循环遍历表(最初是隐藏的)并根据请求的部分显示某些行:
var rows_per_section = [ {min: 0, max: 7}, {min: 7, max: 17}, {min: 17, max: 21}, {min: 21, max: 35}, {min: 35, max: 41}, {min: 41, max: 46}, {min: 46, max: 52},{min: 52, max: 56} ];
var rows_min = rows_per_section[section_no].min;
var rows_max = rows_per_section[section_no].max;
我现在正在尝试使用一个额外的函数来更改脚本,该函数循环遍历表并自行创建 rows_per_section 数组,因为表的长度可以改变。我可以通过查找类标记来检测表中的中断,但我无法弄清楚如何创建数组并在每次遇到中断时添加新值:
function create_section_array(profile_table, no_of_sections) {
var section_counter = 0;
var rows_per_section = new Array(); //this is where it starts to go wrong
//need to create the array and stick in the
//MIN value for the first section as 0
for (i=0;i<profile_table.length-1;i++) {
var table_row = profile_table.item(i);
var row_content = table_row.getElementsByTagName("td");
if(row_content[0].className == "ProfileFormTitle") {
if(section_counter != 0) {
//if not the first section add a MAX value to
//rows_per_section[section_counter + 1]
}
if(section_counter != no_of_sections) {
//if not the last section add a MIN value to
//rows_per_section[section_counter]
}
section_counter++;
}
}
return rows_per_section;
}