html - 在 html5 中使用新的输入类型并保持不支持的回退的正确方法是什么?

标签 html html-input

标题解释得很清楚,基本上我想在这种情况下使用新的输入类型“搜索”,而如果浏览器不支持搜索则回退到 type="text"。

我猜它可能是这样的:

<input type="text" type="search" name="s" placeholder="Search posts">

但我不确定。

这通常是如何完成的?

最佳答案

这是默认行为,也是 HTML5 的设计方式。不受支持的类型将退回到 type=text

来源:Dive into HTML5

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/

相关文章:

javascript - 使用 jQuery 更改输入字段的类型

javascript - 如何更改html中输入类型的值?

javascript - 为 input[number] 中的箭头设置默认值

html - Flexbox - 将元素左对齐并居中

javascript - 在 Firefox 中,输入范围在 mouseup 上触发 "input"事件

html - 我希望我的按钮平放在顶部,带有圆 Angular

html - 出现时在汉堡包图标附近显示下拉菜单

asp.net - Uncaught Error : cannot call methods on popup prior to initialization;

javascript - 如何获取无效 HTML 日期输入的值?