javascript - 在 ios 中使用 contenteditable ="true"显示 div 的键盘

标签 javascript ios contenteditable

我有一个 contenteditable="true"的 div。我如何通过 javascript 将焦点设置在这个 div 上(如果可以在纯 js 上,没有 jquery)?

最佳答案

在 iOS 6 之前这是不可能的,但值得庆幸的是他们已经改变了这一点。一般情况下,您不能为网站执行此操作,但如果您要在应用程序中嵌入 UIWebView,您现在可以执行此操作:

UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
webView.keyboardDisplayRequiresUserAction = NO;

然后您的 element.focus() 将工作并根据需要调出键盘。

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIWebView_Class/Reference/Reference.html#//apple_ref/occ/instp/UIWebView/keyboardDisplayRequiresUserAction

有关 iOS 6 和 WebKit 的变化的更多信息:

http://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html#//apple_ref/doc/uid/TP40012166-CH1-SW19

关于javascript - 在 ios 中使用 contenteditable ="true"显示 div 的键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9766341/

相关文章:

javascript - 按键时使用 Javascript 进入和退出浏览器全屏 View

javascript - 迁移到 Sails.js 0.12 - 中间件迁移

javascript - 如何使用正则表达式检测任何类型的 url

Firefox 光标不可见,单击其他任何内容时变为可见

javascript - 将光标设置到CKEditor中的特定位置

javascript - 是否可以创建当鼠标悬停在 <p> 标记内的文本上时出现的工具提示?

javascript - Select2.js v4.0 : How transmit filter text to ajax source data?

ios - 如何正确实现从 iOS 应用程序到 watchOS2 复杂功能的设置传输

ios - Model View Controller 存储 - 在这种情况下我应该创建多个存储对象吗?

ios - UITableView 滚动到顶部时加载更多数据?