使用 getElementsByTagName
方法找到 first <p>
元素,
并将其文本更改为“Hello”。
<p id="demo"></p>
<script>
@(47) = "Hello";
</script>
<p id="demo"></p>
<script>
document.getElementsByTagName("p")[0].innerHTML = "Hello";
</script>
<p id="demo"></p>
<script>
document.getElementsByTagName("p")[0].innerText = "Hello";
</script>
<p id="demo"></p>
<script>
document.getElementsByTagName('p')[0].innerHTML = "Hello";
</script>
<p id="demo"></p>
<script>
document.getElementsByTagName('p')[0].innerText = "Hello";
</script>