标题解释得很清楚,基本上我想在这种情况下使用新的输入类型“搜索”,而如果浏览器不支持搜索则回退到 type="text"。
我猜它可能是这样的:
<input type="text" type="search" name="s" placeholder="Search posts">
但我不确定。
这通常是如何完成的?
最佳答案
这是默认行为,也是 HTML5 的设计方式。不受支持的类型将退回到 type=text
。
As with all the other new input types, browsers that don’t recognize type="search" will treat it like type="text", so there is absolutely no reason not to start using type="search" for all your search boxes today.
编辑
正如评论中指出的,您不需要两个 type
属性,只需 type=search
:
<input type="search" name="s" placeholder="Search posts">
关于html - 在 html5 中使用新的输入类型并保持不支持的回退的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12225955/