Detecting support for specific HTML 5 features via jQuery

后端 未结 2 2013
天涯浪人
天涯浪人 2021-02-08 08:59

I\'m working on some HTML5 demo code, including stuff like

This currently works correctly in Opera 10 as-is, but every other b

2条回答
  •  不要未来只要你来
    2021-02-08 09:56

    Yeah, checking for a particular browser isn't what you want at all. It's occasionally useful for detecting when you need to apply workarounds for browser bugs (usually with IE), but if you want to know whether a browser supports a feature just sniff for it.

    Some things are easier to sniff than others. For your example of date-input-support it's very easy. The input.type property tells you what type of control the browser thinks it is; if date inputs aren't supported you'll get 'text'.

    
    
    if ($('.dateinput')[0].type!=='date') {
         $('.dateinput').addSomeDateScriptingPluginThing();
    }
    

提交回复
热议问题