检测浏览器是否支持range
昨天的滑块建立在Input range这个基础上 这是IOS5.0及以后才支持的,而且在android2.3以下表现也不对
昨天的检测方式
var input = document.createElement('input'); input.setAttribute('type','range') console.log(input.type == 'range')
不能完全检测出不支持。今天找到了modernizr http://modernizr.com/docs/#installing
看了人家的方式 ,感觉老外真是有耐心啊
inputElem.setAttribute('type', inputElemType = props[i]);
bool = inputElem.type !== 'text';
if ( bool ) {
inputElem.value = smile;
inputElem.style.cssText = 'position:absolute;visibility:hidden;';
if ( /^range$/.test(inputElemType) && inputElem.style.WebkitAppearance !== undefined ) {
docElement.appendChild(inputElem);
defaultView = document.defaultView;
bool = defaultView.getComputedStyle &&
defaultView.getComputedStyle(inputElem, null).WebkitAppearance !== 'textfield' &&
(inputElem.offsetHeight !== 0);
docElement.removeChild(inputElem);
}
}
浙公网安备 33010602011771号