<table border='1' id='output'>
<tr>
<td>
</td>
</tr>
</table>
我的javascript代碼JavaScript的數據添加到表格單元格
document.getElementById("output").childNodes[0].childNodes[0].nodeValue = ajaxRequest.responseText;
不工作,請幫助
<table border='1' id='output'>
<tr>
<td>
</td>
</tr>
</table>
我的javascript代碼JavaScript的數據添加到表格單元格
document.getElementById("output").childNodes[0].childNodes[0].nodeValue = ajaxRequest.responseText;
不工作,請幫助
使用jQueryü可以伊斯利做下面給出:
$(document).ready(function(){
$("#output tr td").text("JQUERY HELP");
});
或者如果u要繼續與JavaScriptü可以參考其他發佈的答案。
我應該只需要導入jquery並粘貼你的代碼?它會工作嗎? – crowso 2011-04-13 06:25:54
耶!下載jquery並在你工作的頁面上使用。 – Sukhjeevan 2011-04-13 06:34:08
document.getElementById("output").children[0].children[0].children[0].innerHTML;
你有兩個錯誤:
<table>
。表必須有<tbody>
標記。這可能是由瀏覽器添加的,這意味着您需要進一步訪問<td>
元素。
第二件事nodeValue
對於非文本節點將始終爲空,這是<td>
。而是使用innerHTML
屬性來更改元素的文本。
糾正這兩件事情之後,你的代碼應該是這樣的:
document.getElementById("output").childNodes[0].childNodes[0].childNodes[0].innerHTML = ajaxRequest.responseText;
我不明白,但它不工作。這是爲什麼 ? – crowso 2011-04-13 06:41:17
<table border='1' id='output'>
<tr>
<td></td>
</tr>
</table>
$(function(){
$('#output td').append("blaa");
});
希望這有助於。
亞歷克斯是對的,有一個tbody TAg。 嘗試下面一個: 的document.getElementById( 「輸出」)的getElementsByTagName( 「TD」)[0] .innerHTML = 「測試1」
你可以分配一個id,你的TD元素,並通過ID被找到更新。 – 2011-04-13 06:25:37