如何构建优雅降级的 HTML5 Range?
我想对支持它的浏览器使用 HTML5 中的 并降级为
不过,我更希望有一些更符合通过 Javascript 进行渐进增强的想法。如果是 JQuery,那就加分了。
I'd like to use the <input type='range' />
from HTML5 for browsers that support it and degrade to a <select />
if not. I'm using Ruby-on-Rails, so failing all else, I could do something like this on the server-side.
I would prefer, though, to have something more inline with the idea of progressive enhancement done via Javascript. Bonus points if it's JQuery.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看Modernizr,它会告诉你是否支持范围。我相信该技术是创建一个范围输入并检查它的类型 - 如果它仍然是“范围”,那么它是受支持的。否则它应该报告“文本”,这是其他浏览器中的后备。
Check out Modernizr, it will tell you if range is supported. I believe the technique is to create a range input and check it's type — if it is still "range" then it is supported. Otherwise it should report "text" which is the fallback in other browsers.
首先检测浏览器是否可以处理 HTML 5,然后使用如下内容:
由于您无法使用
input[type=range]
选择器,所以我必须使用$(item)。 attr('min') && $(item).attr('min')
方法,如果您有其他类型的输入控件具有这两个属性,这会变得有点奇怪。First detect if the browser can handle HTML 5 then use something like this:
Since you can't use the
input[type=range]
selector i had to go with the$(item).attr('min') && $(item).attr('min')
approach, this will get a little weird if you have other types of input controls with those two attributes.