我正在尝试在多个位置动态更新文本。但是我知道下面的代码不起作用,因为同一个 ID 被多次使用。有任何想法吗?
<html>
Favorite things to eat<p id="fruit">Text will appear</p>
Things that grow on trees<p id="fruit">Text will appear</p>
Dinner<p id="fish">Text will appear</p>
Creature in the ocean<p id="fish">Text will appear</p>
</html>
Javascript:
<script>
document.getElementById("fruit").innerHTML="Oranges";
document.getElementById("fish").innerHTML="Shark";
</script>