为了账号安全,请及时绑定邮箱和手机立即绑定

for循环中不存在变量

for循环中不存在变量

人到中年有点甜 2021-06-07 17:43:20
该方案增加了表行for each客户端和内部的table row,一个td客户端的每一个值(如姓名,IP,值等)。这些值和客户端设置在一个key/value object或dictionary称为clientel.我已将程序设置如下:let clientel = {  socket101: ['Rick', '192.590.49.1', 'Win10', 'Norway', '15:49.00'],  socket102: ['Anthony', '192.90.897.0', 'Win7', 'Negritine', '19:19:38']};function man_table() {  const table = document.getElementById('table-body');  for (let i, client in clientel) {    let row = table.insertRow(i);    let index = row.insertCell(0);    let name = row.insertCell(1);    let ip = row.insertCell(2);    let os = row.insertCell(3);    let country = row.insertCell(4);    let timee = row.insertCell(5);    index.innerHTML = i;    name.innerHTML = client[0];    ip.innerHTML = client[1];    os.innerHTML = client[2];    country.innerHTML = client[3];    timee.innerHTML = client[4];  }};function roomba() {  for (let client in clientel) {    console.log(client)  }};我有按 em' 时执行功能的按钮,但出于某种原因,它说clientel未定义?
查看完整描述

1 回答

?
慕斯王

TA贡献1864条经验 获得超2个赞

你不能在循环中分配i和。您需要使用来获取属性值。clientfor-inclientel[i]


let clientel = {

  socket101: ['Rick', '192.590.49.1', 'Win10', 'Norway', '15:49.00'],

  socket102: ['Anthony', '192.90.897.0', 'Win7', 'Negritine', '19:19:38']

};


function man_table() {

  const table = document.getElementById('table-body');

  for (let i in clientel) {

    let row = table.insertRow(i);

    let index = row.insertCell(0);

    let name = row.insertCell(1);

    let ip = row.insertCell(2);

    let os = row.insertCell(3);

    let country = row.insertCell(4);

    let timee = row.insertCell(5);


    let client = clientel[i];

    index.innerHTML = i;

    name.innerHTML = client[0];

    ip.innerHTML = client[1];

    os.innerHTML = client[2];

    country.innerHTML = client[3];

    timee.innerHTML = client[4];

  }

};


function roomba() {

  for (let client in clientel) {

    console.log(client)

  }

};


man_table();

<table id="table-body">

</table>


查看完整回答
反对 回复 2021-06-18
  • 1 回答
  • 0 关注
  • 311 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号