使用 Javascript 在 iOS 中切换键盘
对于 iOS,我可以创建一个按钮来打开和关闭键盘,以便用户可以控制何时在文本框中单击,而不是显示键盘显示键盘?它的 javascript 函数是什么?
请注意,我想用 javascript 而不是 Objective-C 来完成。
谢谢,
For iOS, instead of showing the keyboard any time you click inside a textbox, can I create a button to toggle the keyboard on and off so users can have control over when to display the keyboard? What's the javascript function for it?
PLease note I want to do it in javascript not objective-C.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相当确定没有专用的 JavaScript 方法来控制键盘,但您也许可以使用 jQuery 来伪造它。假设您有这样的文本输入:
您的 JavaScript 代码将类似于:
如果您想向自定义键盘添加一个按钮来调出传统键盘,您会希望它执行:
最后,如果您只想要键盘弹出默认为数字键盘,这听起来对你来说可能是一个很好的附加触摸,你可以通过将你的元素更改为如下所示来告诉 iOS 该元素是数字数字:
你应该能够完成你的任务正在尝试使用这些技巧。
I'm fairly certain there isn't a dedicated JavaScript method for controlling the keyboard, but you might be able to fake it with jQuery. Assuming you have a text input like this:
Your JavaScript code would look something like:
If you want to add a button to your custom keyboard that brings up the traditional keyboard you would want it to execute:
Lastly, if you only want the keyboard that pops up to default to the numbers keyboard, which sounds like it could be a nice added touch for you, you can tell iOS the element is for numbers number by changing your element to look like this:
You should be able to accomplish what you're trying to do with these tips.
@George:我最终决定不需要常规文本框,因为无论如何我都有一个自定义键盘。这样我就不必担心触摸“自定义”文本字段时键盘会弹出。
不管怎样,谢谢你的努力。
@George: I finally decided that I don't need the regular textbox because I have a customized keyboard anyway. That way I won't have to worry about the keyboard popping up when touching my 'customized' textfield.
Anyway, thanks for your effort.