如何强制数字键盘

如何强制数字键盘

本文介绍了iPhone UIWebview:如何强制数字键盘?是否可以?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试验PhoneGap开发一些iPhone应用程序。 PhoneGap基本上包装一个UIWebView - 它工作得很好。问题是我的应用程序有几个输入字段,只接受数字输入。我真的需要强制数字键盘,而不是接受默认的标准键盘,然后强制用户切换到每个字段上的数字。有谁知道这是否可能?如何?



澄清:
我知道苹果目前没有提供任何API来允许这样做。我想知道如果创建继承自UIWebView的自定义类可能会有帮助,或者可能创建自定义键盘会打开一些可能性?



更新6 Nov,2009 - 苹果最近更新了safari功能,这是再次支持。所以接受的答案改变了以反映这一点。

 < html> 
< input type ='tel'/>
< input type ='number'/>
< input type ='email'/>
< input />
< / html>

上面现在按顺序显示以下内容:









解决方案

看起来Mobile Safari支持新的HTML5输入类型, ,搜索, tel url 的属性。这些将切换显示的键盘。请参见。例如,您可以这样做:

 < input type =number/> 

当输入框有焦点时,会显示数字键盘键盘,然后按123按钮。



如果您真的只想要数字,可以指定:

 < input type =tel/> 


我知道这适用于Mobile Safari - 我只认为它将与UIWebView一起使用。


I'm experimenting with PhoneGap to develop some iPhone apps. PhoneGap basically wraps a UIWebView - it works well. The problem is the my app has several input fields that only take numeric input. I really need to force the numeric keypad instead of accepting the default standard keyboard, which then forces the user to switch to the numeric on every field. Does anyone know if this is possible? How?

Clarification:I know that Apple doesn't currently provide any API to allow this. I'm wondering if creating a custom class that inherited from UIWebView might help, or maybe creating a custom keyboard would open up some possibilities?

Update 6 Nov, 2009 - As noted below, Apple has recently updated safari functionality so that this is, once again, supported. So the accepted answer was changed to reflect that.

 <html>
<input type='tel'/>
<input type='number'/>
<input type='email'/>
<input />
</html>

The above now shows the following, in order:

解决方案

It looks like Mobile Safari supports the new HTML5 input type attributes of email, number, search, tel, and url. These will switch the keyboard that is displayed. See the type attribute.

So for example, you could do this:

<input type="number" />

And when the input box has focus, the number keyboard is shown (as if the user had the full keyboard and hit the "123" button.

If you really only want numbers, you could specify:

<input type="tel" />

And then the user would get the phone number dialing keypad.

I know this works with Mobile Safari -- I only assume it will work with UIWebView.

这篇关于iPhone UIWebview:如何强制数字键盘?是否可以?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 16:13