0
當您在以下代碼片段中單擊背景時,將創建一個contenteditable
<span>
。嘗試寫「Hello World」。 空格導致換行符。爲什麼?contenteditable中的空格會導致換行
如何使可用空間中的空格不再導致任何換行符?
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);
window.onclick = function(e) {
var tb = document.createElement('span');
tb.contentEditable = true;
tb.style.position = 'absolute';
tb.style.top = e.clientY + 'px';
tb.style.left = e.clientX + 'px';
wrapper.appendChild(tb);
tb.focus();
}
}
感謝@Moob!我有一個相關的非常棘手的問題在這裏:http://stackoverflow.com/questions/27185427/unwanted-linebreak-in-contenteditable-div 你有什麼想法? – Basj 2014-11-28 09:29:12