There are currently 2 posts.
Font size: Small - 100% (Default)  Content converter: No conversion
 
Clicks Replies
1153 1
Javascript控制文本框中的光标,支持ie,firefox等浏览器
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 1 Posted at: 9/14/14 10:08
/* Functions related to cursor */
var POS_END = -10;
function SetCursorPosition(name, beginning, end)
{
    var obj = $(name);
    if (typeof(beginning) == "undefined")
        beginning = 0;
    if (beginning == POS_END)
        beginning = obj.value.length;
    if (typeof(end) == "undefined")
        end = beginning;
    
    if (obj.setSelectionRange)
    {
        //For IE
        obj.focus();
        obj.setSelectionRange(beginning, end);
        return null;
    }
    else if (obj.createTextRange)
    {
        //For Firefox
        var range = obj.createTextRange();
        range.collapse(true);
        range.moveEnd('character', end);
        range.moveStart('character', beginning);
        range.select();
        return range;
    }
}
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 2 Posted at: 4/5/15 11:05
這個代碼不能控制可編輯html區域中的光標。
Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
(Shortcut key: Ctrl+Enter)
Post Information
Clicks: 1153 Replies: 1
Author: 巨大八爪鱼
Last reply: 巨大八爪鱼
Last reply time: 4/5/15 11:05
Announcements