我正在尝试更改 td 文本。但作为 id 我无法理解我应该添加什么来获取文本。谁能帮忙解决这个问题吗?
我已经添加了?到 getElementBy 到应添加的内容以更改文本。
<html>
<head>
<script>
$(document).ready(function() {
document.getElementBy?('Age').text = 'Años';
});
</script>
</head>
<body>
<table>
<tr>
<td nowrap="nowrap" class="Normal label"> Age:</td>
</tr>
</table>
</body>
</html>
感谢你们的帮助。
最佳答案
没有用于搜索文本的 getElementByXXX
函数。您必须循环遍历所有 td
元素,获取它们当前的文本,并将其与您要查找的内容进行比较。
var tds = document.querySelectorAll('td');
[].forEach.call(tds, function(td) {
if (td.textContent.trim() == 'Age:') {
td.textContent = 'Años:';
}
});
关于javascript - 使用javascript更改td文本而不需要id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38923841/