我有一个 contenteditable="true"的 div。我如何通过 javascript 将焦点设置在这个 div 上(如果可以在纯 js 上,没有 jquery)?
最佳答案
在 iOS 6 之前这是不可能的,但值得庆幸的是他们已经改变了这一点。一般情况下,您不能为网站执行此操作,但如果您要在应用程序中嵌入 UIWebView
,您现在可以执行此操作:
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
webView.keyboardDisplayRequiresUserAction = NO;
然后您的 element.focus()
将工作并根据需要调出键盘。
有关 iOS 6 和 WebKit 的变化的更多信息:
关于javascript - 在 ios 中使用 contenteditable ="true"显示 div 的键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9766341/