Html 在 iPhone/iPad Safari 键盘中显示“搜索”按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4864167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 06:27:53  来源:igfitidea点击:

Show 'Search' button in iPhone/iPad Safari keyboard

iphonehtmlipadsafari

提问by Javier Marín

I've noticed navigating in websites like Dell or Google, that typing in their search text box with iPhone, in the keyboard appears a blue button 'Search' instead of the standard 'Go' button that appears on any normal form.

我注意到在 Dell 或 Google 等网站中导航时,使用 iPhone 在搜索文本框中键入内容时,键盘上会出现一个蓝色按钮“搜索”,而不是出现在任何正常表单上的标准“开始”按钮。

What should you do to display the search button?

你应该怎么做才能显示搜索按钮?

采纳答案by David says reinstate Monica

You can influence this behaviour with:

您可以通过以下方式影响此行为:

<input type="search" />

JS Bin demo

JS Bin 演示

Ignore the submitbutton's text being 'kettle,' I just wanted to be sure that it wasn't the submit button influencing the text of the iOS keyboard...

忽略submit按钮的文本是“水壶”,我只是想确定它不是影响 iOS 键盘文本的提交按钮......

This is, of course, backwards compatible since a browser that doesn't understand type="search"will default to type="text", which is useful for creating forward-planning html5 forms.

这当然是向后兼容的,因为不理解的浏览器type="search"将默认为type="text",这对于创建前瞻性的 html5 表单很有用。

回答by Anton Bielousov

having type="search"is usually all you need to make software Search keyboard appear however in iOS8 it is mandatory to have a wrapping form with actionattribute.

使用type="search"通常是让软件搜索键盘出现所需的全部内容,但是在 iOS8 中,必须有一个带有action属性的包装表单。

So the following code would have a software keyboard with “Return” button

所以下面的代码会有一个带有“返回”按钮的软键盘

<form>
    <input type="search" />
</form>

But this code should have blue “Search” button instead

但是这段代码应该有蓝色的“搜索”按钮

<form action=".">
    <input type="search" />
</form>

回答by Tim

I was not able to get the search button with

我无法获得搜索按钮

<input type="search" />

However, I did get it to appear with

但是,我确实让它出现了

<form>
    <input name="search" />
</form>

回答by dillqvist

On iOS 8 you can enable the blue "Search"-button on the keyboard by doing one of:

在 iOS 8 上,您可以通过执行以下操作之一启用键盘上的蓝色“搜索”按钮:

  • add input name=search
  • add input type=search
  • add id to input with the case sensitive word "search" in the ID, for example the-search or thesearchgod
  • 添加输入名称=搜索
  • 添加输入类型=搜索
  • 将 id 添加到 input 中,在 ID 中输入区分大小写的单词“search”,例如 the-search 或 thesearchgod

回答by Evan Mulawski

The keyboard is handled by the operating system (iOS) and cannot be directly altered. The type of input required determines the type of keyboard to display.

键盘由操作系统 (iOS) 处理,不能直接更改。所需的输入类型决定了要显示的键盘类型。

If the website in question is HTML5, then @David's answer is valid.

如果有问题的网站是 HTML5,那么@David 的回答是有效的。