The method bellow checks if some input type is supported by most of the browsers:
function checkInput(type) {
var input = document.createElement("input");
input.setAttribute("type", type);
return input.type == type;
}
But, as simonox mentioned in the comments, some browsers (as Android stock browsers) pretend that they support some type (as date), but they do not offer an UI for date inputs. So simonox improved the implementation using the trick of setting an illegal value into the date field. If the browser sanitises this input, it could also offer a datepicker!!!
function checkDateInput() {
var input = document.createElement('input');
input.setAttribute('type','date');
var notADateValue = 'not-a-date';
input.setAttribute('value', notADateValue);
return (input.value !== notADateValue);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…