要实现你所描述的修改,你可以按照以下方式修改代码:
for (var i = 1; i <= 12; i++) {
var groupIndex = Math.ceil(i / 4); // 计算当前i所在的组索引
title_val += `
<tr>
<td class="qdd_value">${client_selfloop(groupIndex, i)}</td>
</tr>`;
}
function client_selfloop(groupIndex, currentIndex) {
var startRange = (groupIndex - 1) * 4 + 1; // 计算当前组的起始值
var endRange = groupIndex * 4; // 计算当前组的结束值
return `
LANE1: <select id='client_set_selfloop1${currentIndex}' style='width:115px'><option selected='selected' value=0>关闭</option> <option value=1>打开</option> </select> <button onclick="set_client_selfloop(1, ${currentIndex})" style='margin-left:-3px;margin-top:3px;'>设置</button><br>
LANE2: <select id='client_set_selfloop2${currentIndex}' style='width:115px'><option selected='selected' value=0>关闭</option> <option value=1>打开</option> </select> <button onclick="set_client_selfloop(1, ${currentIndex})" style='margin-left:-3px;margin-top:3px;'>设置</button><br>
LANE3: <select id='client_set_selfloop3${currentIndex}' style='width:115px'><option selected='selected' value=0>关闭</option> <option value=1>打开</option> </select>
<button onclick="set_client_selfloop(1, ${currentIndex})" style='margin-left:-3px;margin-top:3px;'>设置</button><br>
LANE4: <select id='client_set_selfloop4${currentIndex}' style='width:115px'><option selected='selected' value=0>关闭</option> <option value=1>打开</option> </select>
<button onclick="set_client_selfloop(1, ${currentIndex})" style='margin-left:-3px;margin-top:3px;'>设置</button><br>
`;
}
这样修改后,每个组的起始索引会根据当前组索引进行计算,并传递给client_selfloop
函数作为参数。在函数内部,你可以使用这个起始值和结束值来生成相应的内容。请注意,groupIndex
表示当前i所在的组索引,而currentIndex
则表示当前循环迭代的索引值。
内容由零声教学AI助手提供,问题来源于学员提问