jQuery-工具方法-each方法

做~自己de王妃 提交于 2019-11-29 06:43:51
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script src="./jquery.js"></script>
    <script>
        // 使用 each() 方法遍历数组元素
        var colors = ['red', 'green', 'blue'];

        $.each(colors, function(index, color) {
            console.log(index, color)
        })

        // 使用 each() 方法遍历对象属性
        var person = {
            firstName: '莱昂纳多',
            lastName: '小沈阳',
            age: 20,
            gender: 'male'
        };

        $.each(person, function(key, value) {
            console.log(key, value)
        })
    
    </script>
</body>
</html>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!