小编Jos*_*Jos的帖子

插入位置/选择DIV,Textbox,Textarea等

是否存在从不同元素在每个浏览器中获取插入位置和/或选择的完整解决方案.我正在寻找一个我可以执行的解决方案,例如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之前的代码.

javascript firefox internet-explorer caret selection

9
推荐指数
1
解决办法
821
查看次数