How to compare cells in JavaScript table to each other and test for equality? How does indexOf work?

后端 未结 2 891
温柔的废话
温柔的废话 2021-01-07 15:01

I created a table in my HTML code. It has 9 columns and 13 rows. It gets filled up completely by a JavaScript loop that fills it with names of people from a few arrays. Howe

2条回答
  •  忘掉有多难
    2021-01-07 15:28

    You can use the table rows and cells collections for the iteration. The following does a literal comparison of the text content, you may wish to process the text first to "normalise" it in regard to whitespace.

    foobarfum
    fumbarfoo
    foofumfum

    Note that repeated text in a row will be reported twice.

    The above uses the textContent property, which may be supported as innerText in some user agents. It also runs about 10 times faster than the jQuery alternative.

提交回复
热议问题