在编辑按钮的事件处理程序中,对于其他列表中的项目禁用编辑按钮。例如,在JavaScript中:
// 获取所有列表项目的元素 const listItems = document.querySelectorAll('.list-item');
// 获取所有编辑按钮的元素 const editButtons = document.querySelectorAll('.edit-button');
// 遍历每个编辑按钮 editButtons.forEach((button, index) => { // 点击编辑按钮的事件处理程序 button.addEventListener('click', () => { // 禁用其他所有编辑按钮 editButtons.forEach((btn, i) => { if (i !== index) { btn.disabled = true; } });
// 执行编辑操作...
}); }); 在以上示例中,当用户单击编辑按钮时,脚本会禁用其他所有编辑按钮,以确保用户只能编辑一个项目。