日期:2014-05-16  浏览次数:20378 次

js iframe富文本 光标移到文本最后
开发到一个富文本输入框,用iframe做的,现在加一个功能,ctrl+enter在输入框内回车,同时将光标移到换行的那行去显示出来,
参考别人的代码:
JScript code

    //续加<br>ff
   $("iframe").contents().find("body").append("<br>ff");
         var obj=$("iframe").contents().find("body");
         obj.focus();
         var len = obj.html().length;
        if (document.selection) {
            var sel = obj.createTextRange();
            sel.moveStart('character',len);
            sel.collapse(true);
            sel.select();
         } else if (typeof obj.selectionStart == 'number' && typeof obj.selectionEnd == 'number') {
            obj.selectionStart = obj.selectionEnd = len;
         }


还是没能做很效果来,请大家帮下忙,谢谢

------解决方案--------------------
[url=http://topic.csdn.net/u/20080401/14/67f30815-04e8-49cb-9e55-5930dc365046.html]这个可能对你有帮助[/url]