检测浏览器是否支持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);

                    } 
}

 

posted on 2013-07-05 10:42  雨弓  阅读(534)  评论(0编辑  收藏  举报