【发布时间】:2014-04-21 09:40:37
【问题描述】:
我尝试制作一个简单的编辑器框,并希望在其上添加复选框输入。
但是当我添加复选框时,我发现光标没有正确:
插入符号在我添加的复选框之前,即使我按右箭头键也无法正确显示。有什么建议让它更正确吗? (我用的是基于webkit的浏览器,只要改正就可以了。)
我想要实现的是当我单击鼠标或使用键盘定位内容时,插入符号应该像普通编辑器(word、evernote 等)一样工作。
jsfiddler:http://jsfiddle.net/cppgohan/84CTE/9/
HTML:
<button id="add"> AddCheckbox </button>
<button id="add2"> AddCheckbox2 </button>
<div id="editor" contenteditable="true" width="500px" height="500">
1. Make it work <input type="checkbox"><br>
2. Make it done <input type="checkbox" checked>
<div>
JS代码:
$(document).ready(function(){
$("#add").click(function(){
$editor = $("#editor");
$editor.append('<input type="checkbox">');
$editor.focus();
});
...
});
一一按退格键,发生连线事件:
【问题讨论】:
标签: javascript jquery html css contenteditable