English 中文(简体)
将案文添加到TDs和Javascript的Inner/60/8
原标题:Adding text to InnerHTML in TDs with Javascript

I am trying to add text to each cell in particular column via Javascript. Like every 8th TD would be processed for adding text.

Tell me what I have done wrong here/why it doesn t appear in my table:

<script type="text/javascript">
window.onload = function inventorytable() {
var tableRows = document.getElementById

("inventorytable").getElementsByTagName("tbody")[0].getElementsByTagName("tr");

for(var i = 0, l = tableRows.length; i < l; i++) {
    tds = tableRows.getElementsByTagName("td");
    var processor = tds[8].innerHTML += " Ghz"
    var ram = tds[9].innerHTML += " GB"
    var rspeed = tds[11].innerHTML += " Mhz"
}}
</script>
最佳回答

页: 1

tds = tableRows[i].getElementsByTagName("td");

我建议使用:

window.onload = function inventorytable() {
    var tableRows = document.getElementById("inventorytable").rows;
             //or .tBodies[0].rows

    for(var i=0, l=tableRows.length; i < l; i++) {
        var tds = tableRows[i].cells;
        /*processor*/ tds[8].innerHTML += " Ghz"
        /*ram      */ tds[9].innerHTML += " GB"
        /*  rspeed */ tds[11].innerHTML += " Mhz"
    }
}

不界定未使用的变量。 如果你想要澄清其使用,则使用评论。

另外,我用<代码>替换了<条码>。

Update
JavaScript sets are zero-based. So, if you want to refer to the 4th cell, use .cells[3]. At your previous answer, you ve showed a fiddle. see http://jsfiddle.net/ndfh2/.
As you can see, the first row is also getting postfixes. To not add postfixes to these cells in the first row, initiate the counter at one: for( var i=1; .. ; .. )

你目前的法典可能不会奏效,因为你们的浏览量只有12个。 摘录:tds[ number ]上的数字等于一行中的电池指数,从零开始。

问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签