日期:2014-05-17 浏览次数:20647 次
function tableInfo(id) {//把页面的表转为两维数组
?var tr_s = $("tr", $("#grideData"));//grideData是表格的id
?var col_length = 0;
?var rows = $("td,th", $(tr_s[0]));
?$.each(rows, function (i, n) {
??if ($(n).attr("colspan") == null) {
???col_length++;
??} else {
???col_length = parseInt(col_length) + parseInt($(n).attr("colspan"));
??}
?});
?var table_array = new Array();
?for (var i = 0; i < tr_s.length; i++) {
??var col_array = new Array();
??for (var j = 0; j < col_length; j++) {
???col_array.push("#");
??}
??table_array.push(col_array);
?}
?for (var i = 0; i < tr_s.length; i++) {
??var rows = $("td,th", $(tr_s[i]));
??for (j = 0; j < rows.length; j++) {
???var col_num = $(rows[j]).attr("colspan");
???var row_num = $(rows[j]).attr("rowspan");
???if (col_num != null || row_num > 1) {
????if (col_num != null) {
?????var count = parseInt(col_num);
?????for (var c = j; c < (j + count); c++) {
??????if (table_array[i][c] == "#") {
???????table_array[i][c] = $.trim($(rows[j]).text());
??????} else {
???????for (var h = j; h < table_array[i].length; h++) {
????????if (table_array[i][h] != "#") {
?????????continue;
????????}
????????if ($.trim($(rows[j]).text()) != "%") {
?????????table_array[i][h] = $.trim($(rows[j]).text());
????????} else {
?????????table_array[i][h] = $.trim($(rows[j - 1]).text()) + "%";
????????}
????????break;
???????}
??????}
?????}
????}
????if (row_num > 1) {
?????var count = parseInt(row_num);
?????for (var c = i; c < (i + count); c++) {
??????if (table_array[c][j] == "#") {
???????table_array[c][j] = $.trim($(rows[j]).text());
??????}
?????}
????}
???} else {
????if (table_array[i][j] == "#") {
?????if ($.trim($(rows[j]).text()) != "%") {
??????table_array[i][j] = $.trim($(rows[j]).text());
?????} else {
??????table_array[i][j] = $.trim($(rows[j - 1]).text()) + "%";
?????}
????} else {
?????for (var h = j; h < table_array[i].length; h++) {
??????if (table_array[i][h] != "#") {
???????continue;
??????}
??????if ($.trim($(rows[j]).text()) != "%") {
???????table_array[i][h] = $.trim($(rows[j]).text());
??????} else {
???????table_array[i][h] = $.trim($(rows[j - 1]).text()) + "%";
??????}
??????break;
?????}
????}
???}
??}
?}
?return table_array;
}
?
?
?
function changArray(array) {//数组x轴和y轴对换
?var arrays = [];
?for (var i = 0; i < array.length; i++) {
??for (var j = 0; j < array[j].length; j++) {
???arrays[i][j] = array[j][i];
??}
?}
?return arrays;
}
?
function getArrayByTitle(titles, tableInfo, type, types) {//根据文本计算数据下标
?var str = "{";
?if (types == 1) {//左边有全拼行的情况下
??tableInfo = changArray(tableInfo);
?}
?if (type == "col") {
??for (var j = 0; j < titles.length; j++) {
???str += "\"" + titles[j] + "\":[";
???for (var i = 0; i < tableInfo[0].length; i++) {
????if ($.trim(titles[j]) == $.trim(tableInfo[0][i])) {
?????str += i + ",";
????}
???}
???str = str.substring(0, str.length - 1);
???str += "],";
??}
??str = str.substring(0, str.length - 1);
??str += "}";
?} else {
??if (type == "row") {
???for (var j = 0; j < titles.length; j++) {
????str += "\"" + titles[j] + "\":[";
????for (var i = 0; i < tableInfo.length; i++) {
?????if ($.trim(titles[j]) == $.trim(tableInfo[i][0])) {
??????str += i + ",";
?????}
????}
????str = str.substring(0, str.length - 1);
????str += "],";
???}
???str = str.substring(0, str.length - 1);
???str += "}";
??}
?}
?return str;
}