Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Помогите вытащить из таблицы данные... (https://javascript.ru/forum/misc/1650-pomogite-vytashhit-iz-tablicy-dannye.html)

MD6 28.08.2008 14:14

Помогите вытащить из таблицы данные...
 
Есть таблица вида:
<table id="mytable" summary="" border="0" cellpadding="0" cellspacing="0" width="100%">
<colgroup><col width="1%"><col width="35%"><col width="16%"><col width="23%"><col width="25%"></colgroup>
<tbody>

<tr valign="bottom"><td colspan="5" align="left" height="5"></td></tr>
<tr valign="bottom"><td colspan="5" align="left"><font face="" size="2"><b>Table</b></font></td></tr>
<tr valign="bottom"><td colspan="5" align="left" bgcolor="black" height="1"></td></tr>

<tr valign="bottom"><td><img ilo-full-src="" src="" alt=" " height="20" width="5"></td>
<td id="Name" align="left"><font face="" size="2"><b>1</b></font></td>
<td id="Num" align="center"><font face="" size="2"><b>2</b></font></td>
<td id="nce" align="right"><font face="" size="2"><b>3</b></font></td>
<td id="ble" align="right"><font face="" size="2"><b>4</b></font></td>
</tr>

<tr bgcolor="#eieiei"><td><img ilo-full-src="" src="" alt=" " height="17" width="5"></td>
<td headers="Name" align="left"><font face="" size="1"><a href="">11</a></font></td>
<td headers="Num" align="center"><font face="" size="1">12</font></td>
<td headers="nce" align="right"><font face="" size="1">13</font></td>
<td headers="ble" align="right"><font face="" size="1">14</font></td>
</tr>

<tr bgcolor="white"><td><img ilo-full-src="" src="" alt=" " height="17" width="5"></td>
<td headers="Name" align="left"><font face="" size="1"><a href="">21</a></font></td>
<td headers="Num" align="center"><font face="" size="1">22</font></td>
<td headers="nce" align="right"><font face="" size="1">23</font></td>
<td headers="ble" align="right"><font face="" size="1">24</font></td>
</tr>

<tr bgcolor="#eieiei"><td><img ilo-full-src="" src="" alt=" " height="17" width="5"></td>
<td headers="Name" align="left"><font face="" size="1"><a href="">31</a></font></td>
<td headers="Num" align="center"><font face="" size="1">32</font></td>
<td headers="nce" align="right"><font face="" size="1">33</font></td>
<td headers="ble" align="right"><font face="" size="1">34</font></td>
</tr>

</tbody>
</table>



помогите написать скрипт который выталскивал бы данные из таблице например в формате: @11|12|13|14@21|22|23|24@31|32|33|34

jsch 07.10.2008 12:03

ответ
 
<script type="text/javascript">
<!--
window.onload = function(){
    var tbl = document.getElementById("mytable");
    var tbl_arr_tr = tbl.getElementsByTagName("tr");
    var result_arr = new Array();
    for(var i = 0; i<tbl_arr_tr.length; i++){
        if(tbl_arr_tr[i].getAttribute("valign")!="bottom"){
            var tbl_arr_td = tbl_arr_tr[i].getElementsByTagName("td");
            var result_subarr = new Array();
            for(var j = 0; j<tbl_arr_td.length; j++){
                if(tbl_arr_td[j].getAttribute("headers")=="Name"){
                    result_subarr.push("@");
                }
                else if(tbl_arr_td[j].getAttribute("headers")=="Num"){
                    result_subarr.push(tbl_arr_td[j].innerHTML.replace(/\<(\/?[^\>]+)\>/gm,""));
                }
                else if(tbl_arr_td[j].getAttribute("headers")=="nce"){
                    result_subarr.push(tbl_arr_td[j].innerHTML.replace(/\<(\/?[^\>]+)\>/gm,""));
                }
                else if(tbl_arr_td[j].getAttribute("headers")=="ble"){
                    result_subarr.push(tbl_arr_td[j].innerHTML.replace(/\<(\/?[^\>]+)\>/gm,""));
                }
            }
            result_arr.push(result_subarr);
            result_subarr = undefined;
        }
    }
    alert(result_arr);
}
// -->
</script>


Часовой пояс GMT +3, время: 16:09.