输入空div,而contenteditable = true? [英] type in empty divs while contenteditable = true?
问题描述
为什么在启用contenteditable时,光标会不会输入我的某些div?
还有,为什么我的浏览器告诉我,div里面什么都没有显然是一个空格字符?
var div ='< div> < / DIV>;
div.innerHTML = undefined
什么给了?
contenteditable不适用于空元素,因此您可能需要将一个非空格字符插入到您想要编辑的空白元素中。 p>
不间断空间& nbsp;
将作为自己的字符,< br>
,而空格只会在另一个字符后面被计为一个字符
< div>< / div>
----------------> innerHTML = undefined
< div>& nbsp;< / div> ;
--------> innerHTML =
& nbsp;
html字符
所以请确保插入一个& nbsp
而不是
var nbsp =& nbsp;,
div = document.getElementById('id' );
div.innerHTML = nbsp
jquery也是
var div = $('div#id')
div.html(nbsp1)
why won't the cursor enter some of my divs when contenteditable is enabled?
also, why does my browser tell me there is nothing in the div when there is clearly a space character in it?!
var div = '<div> </div>';
div.innerHTML = undefined
What gives?
contenteditable does not apply to empty elements, so you may want to insert a non-breaking-space character into the empty elements you want to be able to edit
the non-breaking-space " "
will act as a character when left on its own,
whereas a whitespace " "
will only count as a character if placed after another character
<div>" "</div>
----------------> innerHTML = undefined
<div>" "</div>
--------> innerHTML =
the gray box around
means its an html character
so make sure you insert a " "
and not a " "
var nbsp = " ",
div = document.getElementById('id');
div.innerHTML = nbsp
jquery works too
var div = $('div#id')
div.html(nbsp1)
这篇关于输入空div,而contenteditable = true?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!