<datalist>
uses autocomplete functionality so this is normal behaviour.
For example if you set input value to be 'o' you will see just orange in datalist options. It checks word from first letter. But if you set input value to 'a' then you won't see options at all.
So if you already have value in input then nothing will be shown in datalist options except that value if it exists. It doesn't behave like select.
Workaround for this would be to use jquery like this for example:
$('input').on('click', function() {
$(this).val('');
});
$('input').on('mouseleave', function() {
if ($(this).val() == '') {
$(this).val('apple');
}
});
Full test here: https://jsfiddle.net/yw5wh4da/
Or you could use <select>
. To me it is better solution in this case.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…