首页 > Web开发 > 详细

JS中对象的定义及相关操作

时间:2015-01-19 20:50:28      阅读:278      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="jquery-1.7.1.js"></script>
</head>
<body></body>
</html>
<script type="text/javascript">
    var obj = {};
    obj = {
        name: 张三,
        friends: [{ name: 小李 }, { name: 小红 }],
        eat: function () { alert(I am eating.); }
    }
     
    // 调用对象中方法
    obj.eat();

    // 遍历对象集合
    $.each(obj.friends, function (index, item) {
        alert(index);
        alert(item.name);
    });
</script>

 

JS中对象的定义及相关操作

原文:http://www.cnblogs.com/mtsl/p/4234602.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!