`
jasin2008
  • 浏览: 68395 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

js object

    博客分类:
  • js
阅读更多
今天在看jquery.selectboxes的src的时候,发现其addoption可以用以下对象添加
var options = {
    "1":"v1",
    "2":"v2"
};

在select中显示就是两个value和text分别为1,v1和2,v2的下拉列表项。
很熟悉是不?json格式
定义了一个object,原来js中的property的命名可以是string的,见js权威指南
7.1. Creating Objects

The easiest way to create an object is to include an object literal in your JavaScript code. An object literal is a comma-separated list of property name/value pairs, enclosed within curly braces. Each property name can be a JavaScript identifier or a string, and each property value can be a constant or any JavaScript expression. Here are some examples:
var empty = {};  // An object with no properties
var point = { x:0, y:0 };
var circle = { x:point.x, y:point.y+1, radius:2 };
var homer = {
    "name": "Homer Simpson",
    "age": 34,
    "married": true,
    "occupation": "plant operator",
    'email': "homer@example.com"
};


利用这个特性,其实可以做为hashtable的简单实现。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics