gpt4 book ai didi

JavaScript:在列表中获取正确的 UI 元素

转载 作者:行者123 更新时间:2023-12-02 15:48:07 25 4
gpt4 key购买 nike

我正在用 JavaScript 构建一个 UI,其中涉及添加一列复选框:

for (var key in ProcessAndPortList.list) 
{
if (ProcessAndPortList.list.hasOwnProperty(key))
{
var dataRow = myTable.insertRow(-1);
var dataCell = dataRow.insertCell(-1);
dataCell.textContent = key;

dataCell = dataRow.insertCell(-1);
dataCell.textContent = ProcessAndPortList.list[key].port;

var terminationCheckbox = document.createElement('input');
terminationCheckbox.type = "checkbox";
terminationCheckbox.id = key;
terminationCheckbox.checked = ProcessAndPortList.list[key].markedForTermination;
terminationCheckbox.onchange = function() {
var isChecked = terminationCheckbox.checked;
markForTermination(key, isChecked);
};
var terminateCell = dataRow.insertCell(-1);
terminateCell.appendChild(terminationCheckbox);
}
}

问题在于将正确的 ID 与选中每个条目的复选框时的回调相关联。我似乎无法获取该函数的复选框的 ID。我只得到最后一个复选框的 ID。如何获得正确的 ID?

最佳答案

改变这个应该有效:

terminationCheckbox.onchange = function() {
markForTermination(this.id, this.checked);
};

关于JavaScript:在列表中获取正确的 UI 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32040331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com