It seems there's not an exact event for this (onchange
is not suitable). However, you can use oninput
and check, if the value of the input
is empty:
document.getElementById('input_ID').addEventListener('input', function () {
if (this.value === '') {
alert('No value');
}
}, false);
This event is triggered also, if user clears the input
with BACKSPACE or DELETE, or cuts the content to the clipboard. oninput
works at least in Chrome, FF, IE10 and Opera.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…