是否存在从不同元素在每个浏览器中获取插入位置和/或选择的完整解决方案.我正在寻找一个我可以执行的解决方案,例如mGetCaretPosition(iControl)将返回其内部元素的插入位置.
我尝试了很多功能:
selection (window/document) [document=IE, window=Opera]getSelection (window/document) [document=Firefox, document=Chrome, document=Safari]selectionStart (input/textarea) [All]craeteRange (selection)createTextRange (selection)
调用document.selection.createRange().text这样的方法不会返回插入位置,因为它没有选择.设置tRange.moveStart('character', - X)时,X不是已知值.当你在div中使用它并且插入符号位于中间时它会占用div之前的代码.