[英]Force lowercase content/HTML of contenteditable div
Is there a fix to allow autocapitalize='off'
on contenteditable
divs instead of using input fields? 是否有允许在可
contenteditable
div上使用autocapitalize='off'
而不是使用输入字段的修补程序?
I've been trying it out in Javascript with attributes and spellchecks, but nothing seems to fix my problem. 我一直在尝试使用Javascript的属性和拼写检查功能,但是似乎没有任何方法可以解决我的问题。 If I apply a rule such as
text-transform: lowercase
, this will make the text you type lowercase, but the actual HTML value is still uppercase (where applicable). 如果我应用诸如
text-transform: lowercase
类的规则,这将使您键入的文本text-transform: lowercase
小写,但是实际的HTML值仍为大写(如果适用)。
How do I ensure it is all lowercase? 如何确保全部为小写?
On contenteditable blur
or focusout
you could replace the content to lowercase: 在内容可编辑的
blur
或focusout
您可以将内容替换为小写:
var editable = document.querySelectorAll('[contenteditable]'); function toLower(){ this.innerHTML = this.innerHTML.toLowerCase(); } [].forEach.call(editable, function(el){ el.addEventListener("focusout", toLower); });
<div contenteditable>THis is some Sample Capital Text</div>
Check text-transform . 检查text-transform 。
div { text-transform: none; }
<div contenteditable>here is the text</div>
Here is the solution - 这是解决方案-
Use CSS to blind the JS effect for user- 使用CSS为用户遮盖JS效果-
*[contenteditable]{
text-transform:lowercase;
}
Then, 然后,
With Native JS- 使用原生JS-
JS- JS-
function changeCase(id){ var txt = document.getElementById(id); txt.innerText = txt.innerText.toLowerCase() }
HTML- HTML-
<div contenteditable onBlur="changeCase('myId')" id="myId">This is Camelcase Text. Type something on me to see effects</div>
With Jquery- 使用Jquery-
JS- JS-
$('[contenteditable]').on('blur',function(e){ $(this).text($(this).text().toLowerCase()); });
HTML- HTML-
<div contenteditable>This is Camelcase Text. Type something on me to see effects</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.