getElementById通过id找到对象

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>index</title>
    <style>
        *{
            font-family: 微软雅黑;
        }
    </style>
</head>
<body>
    <h1 id='hid'>aaaaaaaaaaaaaaaaaaaaaaaaaaaa</h1>    
    <h1>aaaaaaaaaaaaaaaaaaaaaaaaaaaa</h1>    
    <h1>aaaaaaaaaaaaaaaaaaaaaaaaaaaa</h1>    
</body>
<script>
hidobj=document.getElementById('hid');
hidobj.style.background='#ccc';
</script>
</html>

 

posted @ 2020-12-27 22:01  大熊童鞋  阅读(79)  评论(0编辑  收藏  举报