Heim > Fragen und Antworten > Hauptteil
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;
}
其中aqiData[city] = air;是什么意思
怪我咯2017-04-10 17:51:05
var aqiData = {"city":"333","per":"ddd"};
console.log(aqiData["city"]);// 输出 333
反过来就是
aqiData[city] = air;