【发布时间】:2013-10-08 23:23:25
【问题描述】:
json 和 js 的新功能,所以如果有人能教我一点,我会很感激。 json数组:
var info = [
{"t":"09:00","b":"Vaba"},
{"t":"09:30","b":"Vaba"} ] ;
还有JS部分:
var output='';
for (var i = 0; i <= info.length; i++) {
for (info.t of info[i] ) {
output += '<option> ' + info[i].t + ' ' + info[i].b + '</option>'; } };
var update = document.getElementById('start_time');
update.innerHTML = output;
我在 HTML 中得到的结果如下所示:
<option>9.00 Vaba</option>
<option>9.00 Vaba</option>
<option>9.30 Vaba</option>
<option>9.30 Vaba</option>
这是迄今为止我找到的唯一可行的解决方案,但我不需要双重列表(时间和文本字符串两次)。编写任何函数而不是第二个 for 循环都会以错误 info[i] undefined...
结尾先谢谢了。
【问题讨论】:
-
你想知道什么?您可以发布为您引发错误的代码吗?