There are currently 5 posts.
Font size: Small - 100% (Default)  Content converter: No conversion
 
Clicks Replies
1461 4
【英文资料】用jQuery在火狐浏览器下移动文本框的光标
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 1 Posted at: 9/14/14 8:17
http://stackoverflow.com/questions/10725979/set-cursor-textarea-with-jquery-in-firefox
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 2 Posted at: 9/14/14 8:23
http://shawpnendu.blogspot.com/2009/03/javascript-how-to-setget-cursor.html
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 3 Posted at: 9/14/14 8:24
不知phpMyAdmin里面是怎么实现的
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 4 Posted at: 9/14/14 8:32
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
function GetCursorPosition()
{
    // HERE txt is the text field name
    var obj=document.getElementById('textarea');
    var CurPos = 0;
    
    //FOR IE
    if (document.selection)
    {
        obj.focus ();
        var Sel = document.selection.createRange();
        Sel.moveStart ('character', -obj.value.length);
        CurPos = Sel.text.length;
    }
    // For Firefox
    else if (obj.selectionStart == '0')
        CurPos = obj.selectionStart;
    return CurPos;
}

function SetCursorPosition(pos)
{
    // HERE txt is the text field name
    var obj=document.getElementById('textarea');
    
    //FOR IE
    if(obj.setSelectionRange)
    {
        obj.focus();
        obj.setSelectionRange(pos,pos);
    }
    
    // For Firefox
    else if (obj.createTextRange)
    {
        var range = obj.createTextRange();
        range.collapse(true);
        range.moveEnd('character', pos);
        range.moveStart('character', pos);
        range.select();
    }
    
    
}
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <textarea name="textarea" id="textarea" cols="45" rows="5">Basically when we want to create an editor like interface then set or get cursor postion is one of the most important task. Here i want to share two cross-browser supported javascript methods which will meet your requirements To Set cursor position into a TextArea & To Get cursor position from TextArea:</textarea>
  <br />
  <br />
  <input type="button" name="button" id="button" value="Button" onclick="SetCursorPosition(8)" />
</form>
</body>
</html>

这个程序可以在firefox下正常设置光标位置
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 5 Posted at: 9/14/14 8:34

回复:4楼

opera浏览器下正常
ie也正常
chrome也正常
Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
(Shortcut key: Ctrl+Enter)
Post Information
Clicks: 1461 Replies: 4
Author: 巨大八爪鱼
Last reply: 巨大八爪鱼
Last reply time: 9/14/14 8:34
Announcements