0
我有一個由外部軟件自動生成的表格(我必須使用它並且不知道它是如何工作的)。更改DOM表中的文本
我在嘗試將表datafld == "n0"
中的任何項目從15HS01 15F24:HS632401.COUT
改爲15F24
。
我試圖用這個代碼:
// Get all the tables in the document.
var doc_tables = document.all.tags("TABLE");
for (ii = 0; ii < doc_tables.length; ii++)
{
// Process each table.
FireZone(doc_tables(ii).id)
}
// Access the data table object (use the dataFld string)
function FireZone(tableID)
{
// Get the 'specified' table object.
var table = eval("document.all." + tableID);
// Skip the header rows and get to the data rows in table
var nHeadRows = table.rows.length - table.all.tags("TBODY").length;
// Iterate all rows in table....
if(table.rows.length > 0)
{
table
for (i=nHeadRows; i < table.rows.length; i++)
{
table(i).width = 1200;
// Iterate all cells in each row -
for (j=0; j < table.rows(i).cells.length; j++)
{
// Locate cells by "dataFld" - interested in "n0" binding
// Get the Cell value
for (k=0; k < table.rows(i).cells(j).children.length; k++)
{
if(table.rows(i).cells(j).children[k].dataFld == "n0")
{
var value = table.rows(i).cells(j).children[k].innerText;
if (value.search("15F") != -1)
{
table.rows(i).cells(j).children[k].innerText = value.substr(value.search("15F",5));
}
}
}
}
}
}
}
但出於某種原因,這代碼似乎並沒有做任何事情,但是也不它拋出一個錯誤。
與各行對應的HTML塊看起來是這樣的:
<TBODY>
<TR>
<TD style="FONT-FAMILY: Georgia, serif; COLOR: white" noWrap><SPAN dataFld=t0>9/16/2016 11:33:51 AM</SPAN></TD>
<TD style="FONT-FAMILY: Georgia, serif; COLOR: white"><SPAN dataFld=n0>15HS01 15F24:HS632401.COUT</SPAN></TD>
<TD style="FONT-FAMILY: Georgia, serif; COLOR: white" noWrap><SPAN dataFld=v0>0</SPAN></TD></TR></TBODY>
劇本肯定是正在運行,所以任何幫助,將不勝感激。
感謝您的評論,我收到一個錯誤說表不包含方法' querySelectorAll' –