Как пользователь может удалить конкретный элемент из выпадающего списка, а не весь список из выбранного элемента и далее?
<label>
History:
<select id="historySelect">
</select>
</label>
<label>
<input type="button" id="cmbDelete" value="Undo">
</label>
var history = [];
var historySelect
historySelect = document.getElementById('historySelect')
historySelect.addEventListener('change', ()=>{
restoreHistoryAction(historySelect.value)
})
function drawCanvas() {
contextTmp.drawImage(canvas, 0, 0);
history.push(contextTmp.getImageData(0,0,canvasTmp.width,canvasTmp.height))
updateHistorySelection()
context.clearRect(0, 0, canvas.width, canvas.height);
}
Вот код, который у меня есть для добавления истории вв раскрывающемся списке и для кнопки отмены.
function cmbDeleteClick(){
if(history.length<=1)
return
history.pop()
contextTmp.putImageData(history[history.length-1],0,0)
updateHistorySelection()
}
function updateHistorySelection(){
historySelect.innerHTML = ''
history.forEach((entry,index)=>{
let option = document.createElement('option')
option.value = index
option.textContent = index===0 ? 'Start ' : 'Action '+index
historySelect.appendChild(option)
})
historySelect.selectedIndex = history.length-1
}
function restoreHistoryAction(index){
contextTmp.putImageData(history[index],0,0)
}
cmbDelete = document.getElementById("cmbDelete");
cmbDelete.addEventListener("click",cmbDeleteClick, false);
Было бы идеально, если удаляется только выбранный элемент из раскрывающегося списка. Весь код: JS Bin