<td Class='metric' title='Test gave a performance metric.' lastPassTag=''>1997.0</td>
<td Class='metric' title='Test gave a performance metric.' lastPassTag=''>1997.0</td>
<td Class='metric' title='Test gave a performance metric.' lastPassTag=''>1997.0</td>
<td Class='metric' title='Test gave a performance metric.' lastPassTag=''>1997.0</td>
</tr><tr class='detail-hide'><td Class='result-name '>pmu: COMMITTED_PKT_BSB</td>
<td Class='metric' title='Test gave a performance metric.' lastPassTag=''>1655.0</td>
<td Class='metric' title='Test gave a performance metric.' lastPassTag=''>1836.0</td>
<td Class='metric' title='Test gave a performance metric.' lastPassTag=''>1655.0</td>
<td Class='metric' title='Test gave a performance metric.' lastPassTag=''>1836.0</td>
我有一个像上面那样的 HTML 表格 我正在尝试根据应用于那里数字的公式进行条件格式化 我试过这个:
var tb = document.getElementByClass('metric')
我无法获得这些值 任何修改或建议表示赞赏 谢谢
最佳答案
您的代码的唯一问题是您使用错误的 js 上下文来使用 js 搜索类。
document.getElementByClass('metric')
因为类可以超过 1,所以选择类的上下文具有元素而不是像下面这样的元素 应该是元素(复数)而不是元素(单数)
document.getElementsByClass('metric')
希望这能解决您的问题。
如果需要任何其他帮助,请在这里评论我会尽力解决
关于javascript - 如何有条件地格式化我的 HTML 表格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55035940/