是否可以将UIWebView中的第一个字母大写? UIWebview上没有autocapitalizationType属性,例如UITextField和UITextView(例如:textfield.autocapitalizationType = .sentences
)
我在html文件中尝试过
<div id="editor-container" autocapitalize="on" style="padding:0px;margin-top:0px;font-family:'GothamPro-Light';font-size: 15px;"></div>
答案 0 :(得分:0)
请尝试一下。它使用JavaScript在autocapitalize
和words
之间切换none
。我需要在每个input
事件中对div进行模糊()和聚焦()调整,否则键盘将无法拾取autocapitalize
设置中的更改。
<html>
<head>
<script>
function getEditor() {
return document.getElementById("editor")
}
function tickle(editor) {
// This gets the keyboard to pick up the change in the autocapitalize setting.
// Save the selection.
selection = document.getSelection()
anchorNode = selection.anchorNode
anchorOffset = selection.anchorOffset
editor.blur()
editor.focus()
// Restore the selection.
document.getSelection().setBaseAndExtent(anchorNode, anchorOffset, anchorNode, anchorOffset)
}
function textChanged() {
editor = getEditor()
text = editor.textContent
if (text.length != 0) {
editor.autocapitalize = "none"
tickle(editor)
} else {
editor.autocapitalize = "sentences"
tickle(editor)
}
}
</script>
</head>
<body onLoad="getEditor().addEventListener('input', textChanged)"><div id="editor" contentEditable="true" autocapitalize="sentences"></div></body>
</html>