输出属性

2023-07-13T15:30:46.png

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <div id="box">
        这是一个div标签。
        <span>这是一个span标签</span>
    </div>
    <script>
        var box = document.getElementById('box');
        console.dir(box);
        console.log(box);
        console.log(box.innerHTML);
        console.log(box.innerText);

    </script>
</body>
</html>

更改属性

2023-07-13T15:35:32.png

box.innerHTML = "<h1>更改为一个标题标签</h1>";

2023-07-13T15:36:01.png

box.innerText = "更改了文字";