我正在按字母順序篩選表並且遇到問題。我不明白x.innerHTML > y.innerHTML
概念在這個代碼:如何比較innerHTML(JavaScript中的字符串比較)
table = document.getElementById('myTable');
rows = table.getElementsByTagName('tr');
x = rows[1].getElementsByTagName('td')[0];
y = rows[2].getElementsByTagName('td')[0];
//check if the two rows should switch place:
console.log(x.innerHTML.length, y.innerHTML.length);
console.log(x.innerHTML > y.innerHTML);
它是如何工作的?
可能的重複[在JavaScript中比較字符串時爲什麼一個字符串比另一個大?](https://stackoverflow.com/questions/7087811/why-is-one-string-greater-than-the-other - 當比較字符串在JavaScript) – jmargolisvt
僅供參考,你不需要'getElementsByTagName'那裏。 'table.rows [1] .cells [0]'也可以。 – spanky