我正在按字母顺序筛选表并且遇到问题。我不明白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