JS - 事件 -value/innerHTML/innerText区别

value/innerHTML/innerText

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>JS</title>
    </head>
    <body>
        <div id="box">
            <button class="btn">按钮</button>
            <span id="span">
                <a href="#">百度一下</a>
            </span>
            <p>我是段落</p>
        </div>
        <script type="text/javascript">
            window.onload = function() {
            var input = document.getElementById("inp");
            input.value = "嘻嘻";                     //向input写入内容
            var box = document.getElementById("box");
            console.log(box.innerHTML);             //输出div的所有标签
            console.log(box.innerText);             //输出div的双标签的内容
}
         }
        </script>
    </body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_37580235/article/details/80763661
今日推荐