当您在使用contenteditable的页面上创建新的<span>时,键盘光标有时会被放置在Firefox的错误位置。

示例:在下面的片段示例中单击窗口的右侧:将出现"Strawberry“文本,但I键盘光标将位于错误位置。
I如何有一个好的键盘光标位置,用于对象?
window.onload = function() {
var container = document.createElement("div"),
wrapper = document.createElement("div");
container.style.position = "absolute";
wrapper.style.position = "relative";
container.appendChild(wrapper);
document.body.appendChild(container);
container.style.transform = "scale(0.6)";
zoom = 0.6;
window.onclick = function(e) {
if (e.target.className == 'texte') { return; }
var tb = document.createElement('span');
tb.className = "texte";
tb.contentEditable = true;
tb.style.fontSize = '40px';
tb.style.position = 'absolute';
tb.textContent = 'strawberry';
tb.style.top = e.clientY / zoom + 'px';
tb.style.left = e.clientX / zoom + 'px';
wrapper.appendChild(tb);
tb.focus();
}
}<!DOCTYPE html>
<html>
<head>
<title>Text map</title>
</head>
<body>
</body>
</html>
发布于 2014-09-19 10:16:39
运行您的代码片段--对我来说,光标在正确的位置上看起来很好……
https://stackoverflow.com/questions/25931263
复制相似问题