2

I'm trying to move the cursor of a content editable div to the end of the line. By default, it goes to the beginning of the line.

I'm using:

var r = $("#mydiv").createTextRange(); 
r.moveStart("character", l); 
r.moveEnd("character", l);      
r.select();

The error I get:

Uncaught TypeError: Object [object Object] has no method 'createTextRange'

I've seen this question posted around, but I still can't seem to perform createTextRange(). Any suggestions?

4

2 回答 2

0

http://help.dottoro.com/ljouisvm.php

大多数浏览器不再支持 createTextRange() 方法。

您可以用样式化的 textarea 替换该 div 或在 div 内放置一个。

于 2012-07-02T15:25:07.550 回答
0

这是一个 jQuery 插件,您可以尝试一下。

一个小型跨浏览器 JavaScript 库,用于获取和操作 HTML 元素中的选择。

http://code.google.com/p/rangyinputs/

于 2012-07-02T15:59:05.427 回答