嗨,我的朋友我怎么能让这个例子动态化?
请看这张照片
我已经完成了但是还没完成不工作。 谢谢
total 50 static count , Names are changing only
var firstNames = ["Andrew", "Nancy", "Shelley", "Regina", "Yoshi", "Antoni", "Mayumi", "Ian", "Peter", "Lars", "Petra", "Martin", "Sven", "Elio", "Beate", "Cheryl","Michael","Guylene","George","michael","Elio","Sven","Ian","Martin","Yoshi","Guyline","Regina","Beate","Lars","Shelly","Elio","Petra","Cherly","Peter","Antoni","Steven","Adriana","Neomi","Brad","Anthony","Lary","Pit","Adriana","Norton","Daniel","Stefany","Pit","Ivan","Alicia","Demi"];
for (var j = 0; j < 5; j++) { // 5 rows
dynamicTable += '<tr>';
for (var n = 0; n < 10; n++) // 10 cell
{
var name = firstNames[0];// What index should I give here?
dynamicTable += '<td>';
dynamicTable += '<div id='+name+'>';
dynamicTable +="<input type='checkbox' value='"+name+"'>name</input>";
dynamicTable += '</div>';
dynamicTable += '</td>';
}
dynamicTable += '</tr>';
}
dynamicTable += '</table>';
$('#top-panel').append(dynamicTable);
答案 0 :(得分:-1)
你只需要一个设置索引的计数器。
var dynamicTable;
var counter = 0;
var firstNames = ["Andrew", "Nancy", "Shelley", "Regina", "Yoshi", "Antoni", "Mayumi", "Ian", "Peter", "Lars", "Petra", "Martin", "Sven", "Elio", "Beate", "Cheryl","Michael","Guylene","George","michael","Elio","Sven","Ian","Martin","Yoshi","Guyline","Regina","Beate","Lars","Shelly","Elio","Petra","Cherly","Peter","Antoni","Steven","Adriana","Neomi","Brad","Anthony","Lary","Pit","Adriana","Norton","Daniel","Stefany","Pit","Ivan","Alicia","Demi"];
for (var j = 0; j < 5; j++) { // 5 rows
dynamicTable += '<tr>';
for (var n = 0; n < 10; n++) // 10 cell
{
var name = firstNames[counter];// What index should I give here?
counter++;
dynamicTable += '<td>';
dynamicTable += '<div id='+name+'>';
dynamicTable +="<input type='checkbox' value='"+name+"'>" + name + "</input>";
dynamicTable += '</div>';
dynamicTable += '</td>';
}
dynamicTable += '</tr>';
}
dynamicTable += '</table>';
$('#top-panel').append(dynamicTable);