検索

ホームページ  >  に質問  >  本文

javascript - 传递值的问题

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

<code>var aqiData = {};

var cityName = document.getElementById('aqi-city-input');

var airNum = document.getElementById('aqi-value-input');

/**

 * 从用户输入中获取数据,向aqiData中增加一条数据

 * 然后渲染aqi-list列表,增加新增的数据

 */

function addAqiData() {

var city = cityName.value.trim();

var air = airNum.value.trim();

 

if(!city.match(/^[A-Za-z\u4E00-\u9FA5]+$/)){

    alert('请输入中英文');

    return;

}

if(!air.match(/^\d+$/)){

    alert('必须是整数');

    return;

}

 

aqiData[city] = air;

 

}</code>

其中aqiData[city] = air;是什么意思

伊谢尔伦伊谢尔伦2910日前659

全員に返信(3)返信します

  • 高洛峰

    高洛峰2017-04-10 17:51:05

    相当于aqiData.city=air ,给aqiData对象增加了一个名为city的值的属性

    返事
    0
  • 高洛峰

    高洛峰2017-04-10 17:51:05

    就是给 aqiData 赋值的意思,因为这里的city 是一个变量所有不能采用 aqiData.city = air 这种写法。

    返事
    0
  • 怪我咯

    怪我咯2017-04-10 17:51:05

    var aqiData = {"city":"333","per":"ddd"};
    console.log(aqiData["city"]);// 输出 333

    反过来就是
    aqiData[city] = air;

    返事
    0
  • キャンセル返事