js-获取div内容

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript">

        function getElements(){
            var x=document.getElementsByName("div");
            for(var i=0;i<x.length; i++){
            alert(x[i].innerHTML);
            }
        }
    </script>
</head>
<body>
    <div id="1">1231</div>
    <div id="2">qweq</div>
    <div id="3">qw12</div>
    <div id="4">as12</div>
    <div id="5">zx12</div>
</body>
</html>

输出内容

1231
qweq
qw12
as12
zx12
posted @ 2022-12-06 22:23  轻风细雨_林木木  阅读(513)  评论(0编辑  收藏  举报