繁体   English   中英

在ios中显示div的键盘与contenteditable =“true”

[英]Show keyboard for div with contenteditable=“true” in ios

我有一个contenteditable =“true”的div。 如何通过javascript设置焦点(如果可以在纯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

假设contenteditable div的id是'editableDiv',

document.getElementById('editableDiv').focus();

**更新你可以试试div内的东西吗?

<script>
function showKeyboard() {
    document.getElementById('content').focus();
}
</script>
<body onLoad="showKeyboard()">
    <div id="content" contenteditable="true" height="1000">&nbsp;</div>  
</body>

现在在iOS中是不可能的:( https://github.com/jquery/jquery-mobile/issues/3016

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM