作者共發了5篇帖子。
字體大小:較小 - 100% (默認)  內容轉換:不轉換
 
點擊 回復
1460 4
【英文资料】用jQuery在火狐浏览器下移动文本框的光标
巨大八爪鱼
武林盟主 二十一級
回復
1樓 發表於:2014-9-14 08:17
http://stackoverflow.com/questions/10725979/set-cursor-textarea-with-jquery-in-firefox
巨大八爪鱼
武林盟主 二十一級
回復
2樓 發表於:2014-9-14 08:23
http://shawpnendu.blogspot.com/2009/03/javascript-how-to-setget-cursor.html
巨大八爪鱼
武林盟主 二十一級
回復
3樓 發表於:2014-9-14 08:24
不知phpMyAdmin里面是怎么实现的
巨大八爪鱼
武林盟主 二十一級
回復
4樓 發表於:2014-9-14 08: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下正常设置光标位置
巨大八爪鱼
武林盟主 二十一級
回復
5樓 發表於:2014-9-14 08:34

回复:4楼

opera浏览器下正常
ie也正常
chrome也正常
回覆帖子
內容:
用戶名: 您目前是匿名發表。
驗證碼:
看不清?換一張
(快捷鍵:Ctrl+Enter)
本帖信息
點擊數:1460 回複數:4
作者:巨大八爪鱼
最後回覆:巨大八爪鱼
最後回復時間:2014-9-14 08:34
公告板